我對於在我的地圖中爲每個標記分配infowindow存在問題。爲谷歌地圖中的每個標記分配infowindow
JS代碼:
for (i=0;i<location.length;i++){
var id = location[i][0];
var name = location [i][1];
var pos = new google.maps.LatLng(location[i[3],location[i][4]);
var contentString = id;
var infowindow = new google.maps.InfoWindow({content:contentString});
var marker= new google.maps.Marker({position: pos, map: map, title: id});
marker.addListener('click', function() { infowindow.open(map, this);
});
問題是我的點擊處理程序會爲每個標記顯示相同的「id」(id顯示的是我的數據庫中最後一條記錄的id)。 有沒有辦法顯示每個標記的每個infowindow?
[谷歌地圖JS API V3 - 簡單多個標記的例子]可能的複製(http://stackoverflow.com/questions/3059044/google-maps-js-api -v3-simple-multiple-marker-example) – geocodezip