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

后端 未结 5 553
逝去的感伤
逝去的感伤 2020-12-05 09:15

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.LatLngBo         


        
相关标签:
5条回答
  • 2020-12-05 09:40

    This error also 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)       // => error!
    
    0 讨论(0)
  • 2020-12-05 09:43

    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

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

    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);
            });
        });
    });
    
    0 讨论(0)
  • 2020-12-05 09:49

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

    0 讨论(0)
  • 2020-12-05 09:53

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

    0 讨论(0)
  • 2020-12-05 10:05

    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).
    0 讨论(0)
提交回复
热议问题