嘿,我有我的切換標記問題的開/關不能切換標誌谷歌地圖API V3
你有爲什麼切換隻有一個標記(標記「Freilichtmuseum」)任何想法?
thX for help !!
var locations = [
['Sensenwerk', 47.20031715397146, 15.338023278873152, 4],
['Freilichtmuseum', 47.158075170093, 15.315393984492403, 5],
];
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
function toggleLayer() {
if (marker.getMap() === null) {
marker.setMap(map);
}
else {
marker.setMap(null);
}
}
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
你是如何調用該函數togglelayer? – geocodezip 2014-10-16 20:30:46
函數toggleLayer(i) – Manuel 2014-10-16 20:35:14
嗯我不知道爲什麼它只是切換最後的2個標記:/ – Manuel 2014-10-16 20:35:38