2017-09-19 41 views
0

我從數據庫中獲取了緯度,經度和地址。如何顯示在谷歌地圖的每個存儲值:接連在谷歌map.In我的代碼在谷歌地圖上顯示數據庫長期和貸款

$qry = mysqli_query($link,"select * from store"); 
while($row = mysqli_fetch_array($qry)){ 
$lat = $row['lat']; 
$long = $row['lng']; 
$adresse = $row['Adresse']; 
} 

如何顯示的地址各一個店,那隻能說明一個map.how顯示每個地圖?

+0

哪裏是你的javascript產生的地圖? – IsThisJavascript

+0

實際上,您可以使用** PHP **做的是創建一個**數組或Json對象**,您將**通過Javascript循環來創建**標記** ...並且您可以'不要單獨使用PHP來做! – teeyo

回答

0
 //JS function 

    window.onload=initMap; 

    function initMap() { 

      var map = new google.maps.Map(document.getElementById('map'), { 
       zoom: 4,    
      }); 
      show_markers(); 
      } 
/* 
Considering you have php array with locations 
in format ('address'=>add1,'lat'=>lat1,'lng'=>lng1) 
$qry = mysqli_query($link,"select * from store"); 
$marker_data = mysqli_fetch_array($qry); 
*/ 



    function show_markers(){ 
     var locations = <?php echo json_encode($marker_data);?>; 

      for (i = 0; i < locations.length; i++) { 
      marker = new google.maps.Marker({ 
      position: new google.maps.LatLng(locations[i]['lat'], locations[i]['lng']), 
      map: map 
      }); 

      google.maps.event.addListener(marker, 'click', (function(marker, i) { 
      return function() { 
       infowindow.setContent(locations[i]['address']); 
       infowindow.open(map, marker); 
      } 
      })(marker, i)); 
     } 
    } 

reffer地圖相關的代碼:https://developers.google.com/maps/documentation/javascript/adding-a-google-map