我根據搜索結果創建了帶有標記數量的Google地圖(api v3)。當我點擊一個標記時,它會打開一個infowindow。讓infowindow顯示與其標記相關的信息的最佳方式是什麼?與所有標記相關的信息位於我從ajax請求接收的json對象中。如何顯示特定於標記的infowindow中的內容?
for (i=0; i < result.point.length; i++) {
var latLng = new google.maps.LatLng(result.proint[i].Latitude,result.point[i].Longitude);
var marker = new google.maps.Marker({
position: latLng,
title: i.toString()
//map: map
});
markersArray.push(marker);
var infowindow = new google.maps.InfoWindow({
content: 'specific information associated to the marker clicked'
});
google.maps.event.addListener(markersArray[i], 'click', function(event) {
infowindow.open(map, this);
});
鏈接到居住碼將是有價值的。 – andresf 2012-03-08 23:40:40
你想要多個信息窗口還是隻有一個?您的代碼現在的方式是爲每個標記創建一個新的信息窗口,但是隻會顯示最後一個創建的信息窗口。如果你的意圖是隻有一個,那麼你應該把它的創建移出for循環。 – puckhead 2012-03-08 23:52:26
我同意更多的代碼會有幫助,至少是JSON對象。 – puckhead 2012-03-09 00:01:25