2015-08-15 30 views
0

我試圖在Google地圖佈局上顯示標記。我已經嘗試過這種方式,但不會在地圖上顯示標記。在Google地圖視圖中顯示指針

這種方法在第一次顯示地圖時工作正常。位置更新時,新的標記不會在先前加載的地圖上更新。

<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true"></script> 
<script> 
    var locations = []; 
    var map; 

    getLocations(); 

    function getLocations(){ 
     $.post("./../all_donors.php", 
      { 

      }, 
      function (data, status) { 
       var obj = jQuery.parseJSON(data); 
       for($j=0; $j<obj.length; $j++){ 
        marker.push(new google.maps.Marker({ 
         position: new google.maps.LatLng(obj[j]['latitude'], obj[i]['longitude']), 
         map: map 
        })); 
       } 
      }); 
    } 

    function initialize() { 

     var myLatlng = new google.maps.LatLng(9.6667,80.0000); 
     var mapOptions = { 
      zoom: 10, 
      center: myLatlng 
     } 
     map = new google.maps.Map(document.getElementById('page-wrapper'), mapOptions); 

     var marker, i; 

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

      // process multiple info windows 
      (function(marker, i) { 
       // add click event 
       google.maps.event.addListener(marker, 'click', function() { 
        infowindow = new google.maps.InfoWindow({ 
         content: 'Doner Name: ' + locations[i][0] + '<br/>Blood Group: ' + locations[i][3] 
        }); 
        infowindow.open(map, marker); 
       }); 
      })(marker, i); 

     } 

    } 

    google.maps.event.addDomListener(window, 'load', initialize); 


</script> 
+0

很高興看到您遇到了哪些錯誤。 「 – Alex

+0

」顯示錯誤。「 ---它顯示了什麼錯誤?請提供證明您的問題的[最小,完整,測試和可讀示例](http://stackoverflow.com/help/mcve)。 – geocodezip

回答

0

首先,你initialize之前調用getLocations(甚至設置事件偵聽器),並在getLocations你只追加點地圖(這甚至不存在尚未),而不是你的專用positions變量。

由於我不知道你的錯誤信息是什麼,我無法進一步推測,但那只是我注意到的一件事。