Advertisement
Guest User

mishovski

a guest
Dec 17th, 2018
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.25 KB | None | 0 0
  1. <?php
  2.  
  3. $servername = "localhost";
  4. $username = "";
  5. $password = "";
  6. $dbname = "myparkspace";
  7.  
  8. $conn = mysqli_connect($servername, $username, $password, $dbname);
  9. if (!$conn) {
  10.     die("Connection failed: " . mysqli_connect_error());
  11. }
  12.  
  13. $sql = 0;
  14. $sql = "SELECT * FROM geolocations";
  15. $result = $conn->query($sql);
  16.  
  17. if ($result->num_rows > 0) {
  18.     while($row = $result->fetch_assoc()) {
  19.         $id = $row['id'];
  20.         $name = $row['name'];
  21.         $address = $row['address'];
  22.         $municipality = $row['municipality'];
  23.         $city = $row['city'];
  24.         $lat = $row['lat'];
  25.         $lng = $row['lng'];
  26.         $icon_type = $row['icon_type'];
  27.     }
  28. } else {
  29.     echo "ERROR";
  30. }
  31. ?>
  32.  
  33.  
  34. <script>
  35.   function initMap()
  36.   {
  37.     <?php echo "var center = {lat: $lat, lng: $lng}"; ?>;
  38.     var locations = [
  39.     ['<b><?php echo $name; ?> </b><br>\ Grad: <?php echo $city; ?> <br> Opshtina: <?php echo $municipality; ?> <br> Cena: /<br>\ <a href="https://goo.gl/maps/p3DSib4umW32">Get Directions</a>',
  40.      42.0065365,21.4225759, 'parking_garage'],
  41.     ['<b>Testovski parking </b><br>\ Grad: Skopje <br> Opshtina: Test <br> Cena: /<br>\ <a href="https://goo.gl/maps/p3DSib4umW32">Get Directions</a>',
  42.     41.9972736,21.42957, 'parking'],
  43.     ];
  44.  
  45. var map = new google.maps.Map(document.getElementById('map'),
  46. {
  47.     zoom: 9,
  48.     center: center
  49. });
  50.  
  51.  
  52.  var iconBase = 'https://maps.google.com/mapfiles/ms/icons/';
  53.         var icons = {
  54.           parking:
  55.           {
  56.             icon: iconBase + 'green-dot.png'
  57.           },
  58.           parking_garage:
  59.           {
  60.             icon: iconBase + 'yellow-dot.png'
  61.           }
  62.         };
  63.  
  64. var infowindow =  new google.maps.InfoWindow({});
  65. var marker, count;
  66. for (count = 0; count < locations.length; count++)
  67. {
  68.     marker = new google.maps.Marker(
  69.     {
  70.       position: new google.maps.LatLng(locations[count][1], locations[count][2]),
  71.       map: map,
  72.       title: locations[count][0],
  73.       icon:  icons[locations[count][3]].icon, //<- iconBase position
  74.     });
  75. google.maps.event.addListener(marker, 'click', (function (marker, count)
  76. {
  77.   return function ()
  78.   {
  79.         infowindow.setContent(locations[count][0]);
  80.         infowindow.open(map, marker);
  81.     }
  82. })(marker, count));
  83. }
  84. }
  85. </script>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement