-1
所以我試圖做的是當用戶點擊標記時,它會將用戶鏈接到特定的URL,但是它有一些問題,它只是鏈接到最後一個數組的URL。我可以知道爲什麼嗎?爲什麼我的數組無法正常工作[Google Map Api V3]
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」 URL。
非常感謝!我希望我能投票答覆你的答案,但可惜我不能! –