question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Decoded polyline needs escaping of '/' chars

See original GitHub issue

Decoding the following Encoded polyline yields incorrect data (A number of lat,lng pairs were missing)

z``mEm~zv[rNgaALmc@kFg~AMae@zV_gCZqR{y@}F_u@wJ_^_DkN{@cHrkBfd@znA_X|uCsReBcF|j@{fAo\cNsOwIaBqJnFwIge@rFgeAyrBaTsHvdAyJa@cFtj@}GQxt@fhCq@zQp@tEpDxEg@pCPDFvDgA|CiYza@sBrSaS~XMG_ADiMQwBbHOnFmBtS~PnCiKhqAn{@_AeAtHdtAfYhf@mEtGeGb[_k@zA_o@aKwm@nKg@rRsGl\fJvQxJz@uDhCsEpIyChCoB|E{OcF}C@oIfDiTnBcQlCqYlAkHnOe_@jJc^

I discovered I could recover the missing [lat,lngs] by double escaping the ‘\’ characters. The complete and correct encoded polyline becomes:

z``mEm~zv[rNgaALmc@kFg~AMae@zV_gCZqR{y@}F_u@wJ_^_DkN{@cHrkBfd@znA_X|uCsReBcF|j@{fAo\\cNsOwIaBqJnFwIge@rFgeAyrBaTsHvdAyJa@cFtj@}GQxt@fhCq@zQp@tEpDxEg@pCPDFvDgA|CiYza@sBrSaS~XMG_ADiMQwBbHOnFmBtS~PnCiKhqAn{@_AeAtHdtAfYhf@mEtGeGb[_k@zA_o@aKwm@nKg@rRsGl\\fJvQxJz@uDhCsEpIyChCoB|E{OcF}C@oIfDiTnBcQlCqYlAkHnOe_@jJc^

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
n8orescommented, Jan 31, 2017

I was calling polyline.decode() manually from the NPM console (following one of many suggestions found online for decoding polylines).

So yes, while you are technically correct there is still a use case where someone runs polyline.decode(‘xy/z’) directly from the NPM console and it will omit numerous pairs of points.

0reactions
jfirebaughcommented, Jan 31, 2017

You’re conflating or confusing the in-memory representation of a string with representation of a string literal in source code text. polyline operates on in-memory string representation, where there is no notion of escaping, and no need to escape special characters. You only need to escape “manually” if you are passing polyline data as a string literal which is hard-coded into the JavaScript source. In most cases, you pass a polyline string obtained from some other web service or data source.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fixing encoded string for Google Maps polyline - Stack Overflow
I see no issue with that encoded Polyline. There is no need to escape anything. Just enclose the string within simple ' or...
Read more >
Encoded Polyline Algorithm Format | Google Maps Platform
The encoding format within a polyline needs to represent two coordinates ... Note that the backslash is interpreted as an escape character within...
Read more >
What is an Encoded Polyline? – Things I've Figured Out
Depending on what language you're using, or how you're storing the encoded polyline, you may have to escape the escape characters.
Read more >
polyline-encoded - npm
Backslashes in strings should be properly escaped. L.Polygon.encodePath(). Return an encoded string for the current Polygon. Code examples.
Read more >
PolylineEncoder - encode lat/lons to Google Maps Polylines
Default: 1=true. escape_encoded_points. Indicates whether or not the encoded points should have escape characters escaped, eg: ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found