未捕获RangeError:当我尝试设置边界时,超出Google地图的最大调用堆栈大小

我创build了一个工作的谷歌地图,我现在试图自动缩小所以所有的点适合。

当我补充说:

var bounds = new google.maps.LatLngBounds(); 

 bounds.extend(point); map.fitBounds(bounds); 

然后我得到这个错误:

 Uncaught RangeError: Maximum call stack size exceeded J.get (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf J.set (anonymous function) Ey.(anonymous function).zoomRange_changed Zf 

我所有的创build地图的代码是:

 function load() { var map = new google.maps.Map(document.getElementById("map"), { center: new google.maps.LatLng(47.6145, -122.3418), zoom: 13, mapTypeId: 'roadmap' }); var infoWindow = new google.maps.InfoWindow; // Change this depending on the name of your PHP file downloadUrl("getMapMarkers.php", function(data) { var bounds = new google.maps.LatLngBounds(); var xml = data.responseXML; var markers = xml.documentElement.getElementsByTagName("marker"); for (var i = 0; i < markers.length; i++) { var name = markers[i].getAttribute("name"); var type = markers[i].getAttribute("type"); var point = new google.maps.LatLng( parseFloat(markers[i].getAttribute("lat")), parseFloat(markers[i].getAttribute("lng"))); var html = "<b>" + name + "</b> <br/>" ; var icon = customIcons[type] || {}; var marker = new google.maps.Marker({ map: map, position: point, icon: icon.icon, shadow: icon.shadow }); bindInfoWindow(marker, map, infoWindow, html); bounds.extend(point); map.fitBounds(bounds); } }); } 

我刚刚遇到了同样的exception,结果是传入“new google.maps.LatLng”的经度未定义。

可能的情况

  • map.fitBounds(bounds); 没有收到纬度/经度或两者。
  • 收到的纬度/经度值格式不正确(NaN)。

我使用谷歌地图插件: http : //code.google.com/p/jquery-ui-map/我发现自己与同样的问题,作为奥利点,我有我的JSON格式不好。 这是我的json

 mapObj= [      {         "latitude": 57.797333,         "longitude": 12.050211,         "title": "Angered",         "content": "Representing :)"      },      {         "latitude": 57.696995,         "longitude": "11.9865",         "title": "Gothenburg",         "content": "Swedens second largest city"      } ] 

由于经度写成一个string,我得到了这个错误。

求助:把所有的坐标都作为数字。

要添加地图(假设本地JSON,如果没有参考引用链接):

  $('#map_canvas').gmap().bind('init', function() { $.each( mapObj, function(i, marker) { $('#map_canvas').gmap('addMarker', { 'position': new google.maps.LatLng(marker.latitude, marker.longitude), 'bounds': true }).click(function() { $('#map_canvas').gmap('openInfoWindow', { 'content': marker.content }, this); }); }); }); 

将地图中心设置为不支持lat / long也会产生这个错误。