我有以下代码,每次点击其中一个标记时,我会得到第一个infowindow。我有181个infowindows和181个标记。任何帮助赞赏。谷歌地图 - 不知道为什么我总是得到第一个infowindow
var i=0;
$.each(in_locations,function(k,v){
console.log(v);
var marker_latlng = new google.maps.LatLng(v.latitude, v.longitude);
markers[i] = new google.maps.Marker({
position: marker_latlng,
map: map,
title:"here is my title" + v.id
});
infowindows[i] = new google.maps.InfoWindow({
content: "here is some content string" + v.id,
});
google.maps.event.addListener(markers[i], 'click', function() {
alert('number of infowindows: ' + infowindows.length + ' and value is: ' + i);
infowindows[i].open(map,markers[i]);
});
i++;
});
THX
出于某种原因,该的addListener不开火这个。可能有一个次要问题,我没有抓住。让我再看看这个。 thx回答 – timpone 2012-03-28 16:21:36
更新与演示 – 2012-03-28 16:22:25
thx aSeptik,这绝对奏效 - 选择其他答案,因为我正在做一些其他的东西与我的变量。真的很欣赏,因为我刚刚陷入困境。我相信我会有其他问题,并会很乐意接受 - 他们只是非常接近 – timpone 2012-03-28 16:39:55