我正在使用帶有多個標記的Google Maps API &鼠標覆蓋了& infowindows。它完美的作品。現在我想爲CLICK上的每個標記添加一個單獨的網址。但出於某種原因,所有標記始終打開最後一個URL。 - 可能是什麼問題?帶有多個標記的網址
\t // Define your locations: HTML content for mouseover, the info window content, latitude, longitude, url
\t var locations = [
\t ['<h8>Brugg</h8>', '<h7>auseinander.</h7>', 47.4867355, 8.2109103, 'http://www.stadtereignisse.ch/dokumentiert/'],
\t ['<h8>Aarau»</h8>', '<h7>Aarau</h7>', 47.391224, 8.038669, 'http://www.stadtereignisse.ch/erlebt/'],
\t ['<h8>Bern</h8>', '<h7>Bern</h7>', 46.947974, 7.447447, 'http://www.stadtereignisse.ch/erwuenscht/']
\t ];
\t // Add the markers and infowindows to the map
\t for (var i = 0; i < locations.length; i++) {
\t var marker = new google.maps.Marker({
\t position: new google.maps.LatLng(locations[i][2], locations[i][3]),
\t /* title: locations[i][0], */
\t \t url: "http://www.stadtereignisse.ch/dokumentiert/",
\t map: map,
\t visible: true,
\t icon: icons[iconCounter]
\t });
\t
\t markers.push(marker);
\t
\t
\t
\t // CLICK (Allow each marker to have an info window)
google.maps.event.addListener(marker, 'click', function() {
window.location.href = marker.url;
});
// MOUSEOVER
google.maps.event.addListener(marker, 'mouseover', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i)); \t
\t
\t
\t
\t iconCounter++;
\t // We only have a limited number of possible icon colors, so we may have to restart the counter
\t if(iconCounter >= iconsLength) {
\t \t iconCounter = 0;
\t }
\t }
是我還是你在'for'循環中硬編碼了url?似乎你總是使用'http://www.stadtereignisse.ch/dokumentiert/'(並請編輯你的帖子,它是非常糟糕的縮進) – ValLeNain
感謝您的評論ValLeNain! – quiderriere