map.fitBounds(bounds)导致浏览器冻结

use*_*178 8 javascript google-maps-api-3

我有一个非常奇怪的错误,当我尝试调整地图大小以适应我放在它上面的标记时,它会导致我的浏览器冻结.

我的调整大小代码供参考:

 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 
        }
Run Code Online (Sandbox Code Playgroud)

问题是我无法使用firebug正确调试它,因为它冻结了!任何人对问题可能有什么想法?

提前致谢.

更新:

在回答问题时,以下代码显示了填充latlng数组的位置:

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);
                }
            });
        }
Run Code Online (Sandbox Code Playgroud)

puc*_*ead -1

您不会从字符串创建新的 LatLng。它是由 2 个数字创建的,尽管看起来 2 个字符串也可以工作,一个用于纬度,一个用于经度。一根弦是不行的。

所以你可以说new google.maps.LatLng(-25.363882, 131.044922)or Evennew google.maps.LatLng('-25.363882', '131.044922')但不是new google.maps.LatLng('-25.363882, 131.044922') 所以你需要将 2 个单独的值传递给新的 google.maps.LatLng 但看起来你只传递了一个。

http://code.google.com/apis/maps/documentation/javascript/reference.html#LatLng