Uncaught RangeError: Maximum call stack size exceeded Google maps when I try to set bounds

匿名 (未验证) 提交于 2019-12-03 01:06:02

问题:

I created a working google map that I am now trying to have auto zoom out so all the points fit.

When I added:

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

and

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

I then get this error:

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 

All my code for creating the map is:

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 " + name + " 
" ; 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); } }); }

回答1:

I've just run into the same exception, it turned out to be that the longitude passed into "new google.maps.LatLng" was undefined.



回答2:

Possible scenarios

  • Either map.fitBounds(bounds); is not receiving latitude/longitude or both.
  • The received values of latitude/longitude are not in correct format(NaN).


回答3:

I used google map plugin: http://code.google.com/p/jquery-ui-map/ I found myself with the same problem, and as Ollie point, I had my json bad formatted. This was my json

Because of that longitude written as a string, I was getting that error.

SOLVED: Having all coordinates as numbers.!

To add the map (assuming local json, if not refer to reference link):

    $('#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);         });     }); }); 


回答4:

Setting map center to a not supported lat/long also produces this error.



回答5:

Also, the error seems to be raised when you set NaN as the value of zoom.

map.setZoom(null)      // => nothing happens map.setZoom(undefined) // => nothing happens  map.setZoom(NaN)       // => collapse 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!