0

我在使用其JavaScript API的谷歌地圖中有幾個標記,並且我想在點擊標記頂部顯示信息窗口,但是當您點擊其中一個標記時打開最後一個標記中的信息窗口而不是在相應的標記,樣本代碼:離子,如何在Google地圖上顯示正確的infowindow?

for(var i = 0; i < points; i++) { 
     var randomLatLong = new google.maps.LatLng(position.coords.latitude + getRandomArbitrary(-radius, radius), position.coords.longitude + getRandomArbitrary(-radius, radius)); 

     var marker = new google.maps.Marker({ 
      map: $scope.map, 
      animation: google.maps.Animation.DROP, 
      position: randomLatLong, 
     }); 

     var infoWindow = new google.maps.InfoWindow({ 
      content: "Here is something to see!" 
     }); 

     marker.addListener('click', function() { 
      infoWindow.open($scope.map, marker); 
     }); 
    } 

這裏是一個codepen:

http://codepen.io/ospfranco/pen/yOPpey

只需輕按上的標記之一,TE信息將在其他標記

打開10

任何人都知道如何解決這個問題?

回答

1

只需在聽衆中將'marker'更改爲'this'即可。

marker.addListener('click', function() { 
      infoWindow.open($scope.map, this); 
     }); 
+0

這是有效的,但爲什麼'marker'不工作? – ospfranco

相關問題