Skip to content Skip to sidebar Skip to footer

Google Maps Decode Path (polyline) - Uncaught Syntaxerror: Unexpected Token Illegal

I have problem with decoding string to function from Google Maps. I have error: Uncaught SyntaxError: Unexpected token ILLEGAL. I don't know what I should to do. Maybe problem i

Solution 1:

You need to "double encode" the \ characters inside the string. I did a search and replace of \ with \\ and it works.

related question: Plot polyline in Google Maps

code snippet:

functioninitialize() {
  var map = new google.maps.Map(
    document.getElementById("map_canvas"));
  var decodedPath = google.maps.geometry.encoding.decodePath("i|ftHkwjlBCEF]HNVjA`@nA\\hA`@nAD`ABt@Bz@Zf@b@Zn@^x@\\|@PbAPbADx@DrAEpAUtAk@lAcAjA_AzAe@pAm@lA_AbAcB`AmBx@iBl@eBr@qBd@{BX}BXsBTqBu@QJk@h@cAJiBBmBFwAKyA@}@DA@A???????????@AFANAl@Bn@@d@EbAChAGxAQdBa@r@_@d@JH`@Lh@Td@Rh@Tr@Xr@Zj@T`@f@PxA~@hBjAt@fAH|@\\xASx@eB\\uAn@t@~@bA~@l@jB~@nAh@nAh@pAp@jA~@x@hAz@lAv@d@t@e@|@q@lA}@nBeBjAcAz@u@`Aq@|@u@hAaAhAeAv@k@^b@\\pA^xA^vAVhAb@zAVrA]V{@Xy@d@k@\\s@b@q@`@o@\\m@XeAj@gAj@gAd@aAh@{@l@u@n@{@l@m@f@y@j@m@f@m@d@mA`Ak@h@u@j@k@b@m@b@s@f@k@\\q@h@i@^q@d@[RGD@A@E@CCB@?@DA??????????????E?GAB?FCA?@@@BBZWh@a@b@WJE?AA?????????????????????RS`Aq@fA{@|@q@bAy@bAy@rAeArAiApAcAtAeAtAeArAu@vAo@~@i@t@g@jAg@lAq@hAm@~@k@hAYDiB_@aBc@aBg@eBYqAi@yAcAl@qAjAeAh@}@[}AV}B\\wAb@aAVeArAiAtAeAT_AA}@EoAe@cA]aAg@mAo@iAk@iAs@aAiAeAi@]`A[bAk@~@y@Ew@]eAO}@Ku@kAy@kAC_Be@Ww@Wy@_@}@a@u@[y@[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`BVlAZxAd@~BZ|AZzA\\xA\\vAVdAXrAV|@Nx@[f@s@c@uAz@m@`@u@l@o@b@m@j@k@h@u@p@q@t@k@n@q@r@m@t@kArAq@b@o@PCv@IL?CA@?@???@?A@?A?@C?@?@??????????????????????ALIJSXU`@]j@U`@Wb@[l@[j@]n@[l@U`@Sd@[l@Wl@Wj@Ub@Sh@[r@g@nAUf@Yn@Un@Yx@Ur@Sl@Qj@Sp@Oh@St@Wx@Sx@Ol@Od@Or@Qr@Qv@Qx@Qt@Q|@Oz@Mp@QbAMt@M|@Mz@Ir@M~@Kr@Ix@Kx@Gj@Kl@Kr@MfAKx@M~@M|@Ov@Kn@Kn@Mx@Ox@Ih@I\\BC???ACGBWFe@Ha@Ji@Ho@Jo@Jq@N{@RqAHo@L}@Ju@L{@Hw@Hm@Ho@Ly@L_AJ{@Jw@L_ANeALs@Jm@N{@Lm@Ny@Nw@P{@Nu@Nm@ZoANk@Ru@Rs@Tu@V}@Vw@Tw@Vq@Rm@Pk@Vs@Zu@Zw@Tk@Ve@Xq@Xo@Zq@Vg@Te@Vi@Vg@\\o@\\m@Xi@Xe@^q@\\g@Ta@Xe@X]H]?BEBC??@AA@@??A?A???????@??A@A??CD@G?@???@??????@@?A@@BM@K?A??B??BBA@B??@A?@?A??@????A?@D??AABAA??A@?A?@???A?@A????@A?@AA??@@@????D@CAA????????????????????????????????????A??????@???????????????????????????????????????????????????????????????????????????????????????@?????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????NNx@M^j@T?@[AA?@?MFC?A?A?????BA@??@???????????????????????????@S?A?????@????????????????@DCHGPGp@Sm@SU]BUNYMSRKR??A@A?????????????????DBRc@XCh@Kd@NVp@Fg@@_@A?BI???@????????????B?A?@AA??@??????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????B?F?PW`@c@h@i@h@g@x@w@f@e@d@_@DC??@???A@TUd@_@x@i@~@o@t@c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@CCBG?GBKF?LFPALQBODSPMNMPKTKNKTGPGXIRGP?RCDENCF?RALGRGTQFQDG@Q?SAQCM@OLGPIPOFOBKAGC?AA?B?DBB?IAB?LEJEHCJCDC@EDOLKJCN@N@PDL?LAJANEBC?Q@S?SBQBSHSBYFWHQDQHSJWJSJOLMJOLMJCJIH?HABA?EEECSDM@?BADEDABAFC@B@?A??????@@B???@AA?@?A@C?AFEJOP]TQTOXMX?ZE`@E^Ob@Qd@Sh@K^I`@G`@Kh@Gj@Zh@h@b@Nn@a@h@c@Zy@f@u@v@Yl@@n@Ob@[?{@GiAGcAEs@G_AIiAIkAGoAIyAG{ACqAEkACkACcAAcAA}@Bo@ZMb@KFCIa@`@?p@Gl@Gl@G|@Il@Gt@Cl@Ar@Ev@Yj@Uf@[l@Ip@Kp@Gr@Lt@Er@Kr@Bl@Dl@Aj@Ol@Qj@Un@_@x@a@t@c@l@a@p@a@`Ac@vA[t@{@^c@BOCSC[Em@Q}@MgAGkAEaALq@b@g@Li@O}@OcAS_AQ_AO{@Mg@@GAGAGEMCE@Gb@SDG?GAGAI?EFEZWd@FZc@XKf@^j@Nf@a@h@a@b@e@^e@`@i@j@k@\\]^g@l@u@?_A[m@ST_@r@]p@GD@AC?AC@?@A??@@???????????AAEJIFN@@@@C@?BA??????????????????@C?A@G@C?@A?@?@????????A@?@???CAA?A?@???CBC@???@???A@?A????????????????????????????AICCA?@B?@@@?????????????@????????????????????????????@?AA????????????@@??");

  var polyline = new google.maps.Polyline({
    path: decodedPath,
    map: map
  });
  var bounds = new google.maps.LatLngBounds();
  for (var i = 0; i < polyline.getPath().getLength(); i++) {
    bounds.extend(polyline.getPath().getAt(i));
  }
  map.fitBounds(bounds);

}
google.maps.event.addDomListener(window, "load", initialize);
html,
body,
#map_canvas {
  height: 100%;
  width: 100%;
  margin: 0px;
  padding: 0px
}
<scriptsrc="https://maps.googleapis.com/maps/api/js?libraries=geometry&key=AIzaSyCkUOdZ5y7hMm0yrcCQoCvLwzdM6M8s5qk"></script><divid="map_canvas"></div>

Post a Comment for "Google Maps Decode Path (polyline) - Uncaught Syntaxerror: Unexpected Token Illegal"