I have my google map codes running for time where I can draw polygon and polyline without issue. Below are my snippet of codes on how I do my drawing. Unfortunately I got this error Uncaught RangeError: Maximum call stack size exceeded main.js.27. I notice that the error is at this line drawingManager.setDrawingMode(null);. The moment I comment this line all works fine. Is there a bug in function now ?

google.maps.event.addListener(drawingManager, 'overlaycomplete', function(e) {
           var points = e.overlay.getPath();
           geoFenceString = "POLYGON((";
           var latlngbounds = new google.maps.LatLngBounds();
           for (var i =0; i < points.length; i++) {
               var xy = points.getAt(i);
               geoFenceString = geoFenceString+xy.lng()+" "+xy.lat()+",";                         
           geoFenceString = geoFenceString+points.getAt(0).lng()+" "+points.getAt(0).lat();     
           geoFenceString = geoFenceString+"))";
           var htmlString = '<table idth="100%">\r\n';
           htmlString += '<tr><td>Name</td><td valign="top"><input id="geoFenceName" type="text" style="width:100%" value=""></td></tr>\r\n';
            htmlString += '</tr>\r\n';
            htmlString += '</table>\r\n';
            var infowindow = new google.maps.InfoWindow({


I can double confirm this because when I run codes from this link https://gist.github.com/rafalgalka/5765919 also give me same error.

  • Confirm that, I have found that while I use polygoncomplete and then use drawingManager.setDrawingMode(null); polygoncomplete enters infinite loop which is resulting in same error as above. – scx Jan 21 '15 at 10:41

keep a check before setting the drawingMode to null.


That should work.

  • Nope ranadhir that does not work at all at it comes out with the same error. – user4126382 Jan 20 '15 at 22:17

I came across this issue during january. I solved it with the logic "if drawing mode is already null, then don't try to set it to null again".

google.maps.event.addListener(drawingManager, 'polygoncomplete', function (polygon) {
    if (drawingManager.getDrawingMode() === null) {
    } else {
        ... do your stuff ...

Usually "do your stuff" involves setting Drawingmode to null, so checking for a null drawing mode aims to check if you already "did your stuff".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.