我有一個非常奇怪的錯誤,當我嘗試調整地圖大小以適應放置在其上的標記時,導致瀏覽器凍結。map.fitBounds(bounds)導致瀏覽器凍結
參考我的大小調整代碼:
function sizeMap() {
// create a new bounds object to define the new boundry
var bounds = new google.maps.LatLngBounds();
// loop through each the string latlang values held in the latlng
// aray
for (var i = 0; i <latlngArray.length ; i++) {
// create a new LatLng object based on the string value
var tempLatLng = new google.maps.LatLng(latlngArray[i]);
// extend the latlng bounds based on the new location
bounds.extend(tempLatLng);
}
// map.fitBounds(bounds); <== everything seems to work fine until this line is uncommented
}
問題是我不能正確地調試它使用Firebug,因爲凍結到了! 任何人對這個問題可能有什麼想法?
在此先感謝。
更新:
在回答puckheads質疑下面的代碼顯示了經緯度陣列填充入手:
function geocodeAddress (address) {
var geocoder = new google.maps.Geocoder();
geocoder.geocode({'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
loadMarker(results[0].geometry.location,"Info here",address);
latlngArray.push(results[0].geometry.location); <== latlngs are first added here they are as a result of a call to the google geocode service with a standard string address.
} else {
alert("Geocode was not successful for the following reason: " +" "+ status);
}
});
}
您是否解決了這個問題? - 如果是的話,你應該接受或寫出你自己的正確答案! – levi 2014-07-08 15:43:03
您是否嘗試過使用Chrome和JavaScript控制檯? – MrUpsidown 2015-04-21 11:37:00