所以我想做的是当用户点击标记时,它会将用户链接到特定的 URL,但是它有问题,它只链接到最后一个数组 URL。我可以知道为什么吗?
for (var key in places){
var myPlace = places[key];
if (myPlace) {
var marker = new google.maps.Marker({
map: map,
url:myPlace.infowin_html,
position: new google.maps.LatLng(myPlace.position.lat, myPlace.position.lng)
});
createTooltip(marker, key);
google.maps.event.addListener(marker, 'click', function() {
window.location.href=marker.url;
});
}
}
我的js
var places =Array();
places.push({
infowin_html:"https:www.facebook.com",
tooltip_html:"<div><img src='http://upload.wikimedia.org/wikipedia/commons/thumb/7/76/Habs_flw_oak_park_home.jpg/220px-Habs_flw_oak_park_home.jpg' width='220' hieght='174' /></div><h3>Chow Kit, KL</h3><div><stong>Population:</strong> 52k</div>Click for more..",
position:{lat:3.1597, lng:101.7000}
});
places.push({
infowin_html:"https:www.facebook.com",
tooltip_html:"<h3>Subang Jaya, Selangor</h3><div><stong>Population:</strong> 2.7m</div>Click for more..",
position:{lat:3.0394, lng:101.5878}
});
places.push({
infowin_html:"https:www.facebook.com",
tooltip_html:"<h3>Puchong Jaya, Selangor</h3><div><stong>Population:</strong> 74k</div>Click for more..",
position:{lat:3.0113, lng:101.6115}
});
places.push({
infowin_html:"asd",
tooltip_html:"<h3>Cyberjaya, Selangor</h3><div><stong>Population:</strong> 55k</div>Click for more..",
position:{lat:2.9225, lng:101.6550}
});
我得到的是“asd”网址。