Resolving Error “Maximum call stack size exceeded” When Using Google Maps API

September 5th, 2013 - Posted by Steve Marks to Javascript / jQuery, Web Development.

I love working with the Google Maps API and have been lucky enough recently to work with it in a few projects; From simple maps with just a couple of markers, to complex maps showing polylines, polygons, directions, and much much more. Hopefully I’ll get to share some of these more advanced maps with you in the near future.

A couple of times when working with the API in these more advanced situations, I’ve come up against the following JavaScript error appearing in the console and thus, preventing my map from appearing:

Uncaught RangeError: Maximum call stack size exceeded

To be honest, it’s a pretty useless error. It doesn’t tell me anything to do with what the cause is, or where to look. In code that contains thousands of lines this can be a pretty hard one to diagnose.

Luckily for the readers amongst you in the same situation, I managed to find the cause of the error and hope the solution fixes it for you also.

The Solution

The cause for the error in my map was that an invalid latitude and/or longitude was being used when creating a polyline like so:

var polylineCoordinates = [
    new google.maps.LatLng(37.772323, -122.214897),
    new google.maps.LatLng(21.291982, -157.821856),
    new google.maps.LatLng(-18.142599, 178.431.1156),
    new google.maps.LatLng(-27.46758, 153.027892)

var polyline = new google.maps.Polyline({
    path: polylineCoordinates,
    strokeColor: '#FF0000',
    strokeOpacity: 1.0,
    strokeWeight: 2,
    map: map

Take a look at the above code. Can you see that one of the longitudes, ‘178.431.1156‘, being used isn’t valid? After fixing this and making it a valid set of co-ordinates, the polyline should then begin to appear.

Note that in the example above I’ve only referred to polylines. I believe the error in question will also be thrown when using invalid co-ordinates for other overlays (rectangles, polygons etc).

This entry was posted on Thursday, September 5th, 2013 at 1:43 pm by +Steve Marks and is filed under Javascript / jQuery, Web Development. You can follow any responses to this entry through the RSS 2.0 feed.

Fear not, we won't publish this

Comments (0)

No comments have been left yet. Be the first