apneadiving / Google-Maps-for-Rails

Enables easy Google map + overlays creation in Ruby apps
https://apneadiving.github.io/
MIT License
2.27k stars 382 forks source link

Adding polyline with bounds.extendWith() causes error: Uncaught RangeError: Maximum call stack size exceeded #504

Closed rorykoehler closed 8 years ago

rorykoehler commented 8 years ago

I have the following code where I take the Google encoded polyline algorithm format string and decode it into an array for use with the addPolyline function. Adding it to the map with bounds.extendWith() causes multiple 'Uncaught RangeError: Maximum call stack size exceeded' errors. Am I doing this right or is there another step I'm missing?

My code is:

handler = Gmaps.build('Google');
type = 'Ride';
if( type === "Ride") {
  zoom = 10;
}else{  
 zoom = 14;
}
decodedPath = google.maps.geometry.encoding.decodePath('yllGmbexRm@qBpAtBgFRuRy]{s@hJ{Y}MeErAdD_A{n@sMg@cMbEnLcGBcA`Wl@qYxDsKpz@g@DsG}t@iMit@AaBkVzGaW|B}x@aE_V[ii@u_@avB~JiVaFgWbJi_@oBad@nUyf@nB{Va`@}rAwjAm~@~KiKtSul@et@e|@iCiJ`CkKt]c[da@yz@tWiMlOs`@qL_EwChFcQwUoAeXsFoN^kQrN}Gx]uCqNpAIcRtLoH~GD`SiO~Qqd@dOwIng@iLxa@v^mRxRoSjG~@yC_KmR}Cc@_DzEsI`@{JjSkZpZiVfKqa@fDeO~Fe@lUfFdK]zP`CdH|OfTzDwEbLtDsMba@oWvLqc@r|@e]`ZkBjLdy@dfAwXn|@bm@rm@pSnL~_@nqA_B|XmTfb@`Bxf@}I|^~E|WeK~Uz_@`yB^|j@pDjU}Bvu@wG`Ux@hShAzCtn@c@n]lFqCjFip@mH{EtRhAr_@lLlBrTxNjh@dGh[dMz{@sQdH|H`I}@');

  handler.buildMap({
    provider: {
      disableDefaultUI: true,
      zoom: zoom,
      center: {lat: 1.38, lng: 103.74}
      // pass in other Google Maps API options here
    },
    internal: {
      id: 'map'
    }
  },
  function(){
    polyline = handler.addPolyline({
      path: decodedPath,
      geodesic: true,
      strokeColor: '#FF0000',
      strokeOpacity: 1.0,
      strokeWeight: 2
    });
    handler.bounds.extendWith(polyline);
    handler.fitMapToBounds();
  } );
apneadiving commented 8 years ago

Hi, I looked at your issue and did a jsbin to test: http://jsbin.com/miguqo/1/edit?js,output The point was to respect the signature of addPolyline: fn([{ lat:, lng }], options)

Hope it helps

rorykoehler commented 8 years ago

Ok, great to know. Thanks for your time and help.