我正在處理的問題,我的谷歌地圖頁面顯示我在Firebug中的錯誤。 當我在我的經銷商地圖中搜索時,會觸發clearLocations()函數。 但這個錯誤是顯示了起來:「標記[I] .setMap不是一個函數」谷歌地圖setMap不是一個功能
有誰知道如何解決這個問題呢?我搜索了幾個論壇和組,但我使用的是google.maps.Marker數組,所以我找不到我的問題。
在此先感謝!
代碼(clearLocations()):
function clearLocations() {
infoWindow.close();
for (var i = 0; i < markers.length; i++) {
markers[i].setMap(null);
}
markers.length = 0;
dealers.innerHTML = "";
}
代碼(負載()):
function load() {
map = new google.maps.Map(document.getElementById("map_canvas"), {
//center: new google.maps.LatLng(51.30174, 10.60824),
zoom: 10,
mapTypeId: 'roadmap',
mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU}
});
infoWindow = new google.maps.InfoWindow();
dealers = document.getElementById("dealers");
infoWindow = new google.maps.InfoWindow();
var bounds = new google.maps.LatLngBounds();
for (i = 0; i < markers.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(markers[i][1], markers[i][2]),
map: map
});
var pos = new google.maps.LatLng(markers[i][1], markers[i][2]);
bounds.extend(pos);
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(markers[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
map.fitBounds(bounds);
}
這是否制定出適合你? – Idiot211
爲我解決了問題,謝謝 – Abram
這爲我解決了問題,謝謝!這是問題,我的標記數組是一個lat/longs的對象,而不是標記本身。 –