4

By making Google Maps API call I received a response JSON which contained this polyline:

ezdvBcps}Lt@W@F@BVKl@UK]Wc@}@kAOKBEzA{BdA}Ab@s@LBf@RjARZBv@?rAAfBIX?f@FLBf@^b@hATbAF~@BvB?hALjBHpCLjAVdAd@dAxCbGlA~BbBvCpAbD`AnCVpB\\hBf@nB|@tAb@f@RVXLbDj@jCl@nAf@`DbBdC`B`@b@HNN`@lA~DnAvBvB`G\\fA^p@j@z@~E`FbBpBxDfFXh@|@pD`@bB^fANd@\\`Bl@rBb@fATj@v@bBjBwCd@w@NB^B\\@\\K\\Q|AWZGXOPIRBb@K\\Kl@_@VOZWVI^Eh@Ov@KxCJ\\@\\K^@RMh@QhAMXKXY`@Q^SLK`@]fBc@n@M\\OlB_@n@KNMRUZQZGh@Ht@Lx@F`@BTANDRNTPNDDHLXN`@LRTJx@?RBJFFLV\\Zs@TQ`@MVIhAYp@YPc@VgALk@Hk@d@eA\\cAHq@Eo@J}@@q@DItAgAv@i@|@e@v@k@bAaAdDuB|@c@?I?]?{@Ms@COFWJODYEcABOTU^e@H_@Km@Ci@BU?e@Ca@Ie@e@oBKk@Eu@M{@CoAC}@Km@Iy@IaA?{@Ci@Ms@UgA]y@Mm@GQICe@QKMGi@Gi@GSI[Ym@[{@@_AK]SMo@i@OCg@EOEMMYSi@IUO]Ko@KSIWUWMU_@I]Kw@WoACY@a@CWQWe@[QIOYMYW]SMQUQu@OWWSUWU[SsAEg@Ic@Mc@?a@Ai@Em@AUOa@M_@e@g@MSGYOY_@YIQSR[Pa@mBQaAI[@QDyACq@Iu@o@k@e@Y]IcAAmBC]Ee@IgAUWAw@Ae@GWSaAeAYk@Si@a@k@YAc@O{@]a@MnAqA~@mCVaAHk@YmCIQSQOS

See https://developers.google.com/maps/documentation/utilities/polylineutility

I wanted to decode it in Python. So, I tried out polyline package (github link):

>>> import polyline
>>> l = polyline.decode('ezdvBcps}Lt@W@F@BVKl@UK]Wc@}@kAOKBEzA{BdA}Ab@s@LBf@RjARZBv@?rAAfBIX?f@FLBf@^b@hATbAF~@BvB?hALjBHpCLjAVdAd@dAxCbGlA~BbBvCpAbD`AnCVpB\\hBf@nB|@tAb@f@RVXLbDj@jCl@nAf@`DbBdC`B`@b@HNN`@lA~DnAvBvB`G\\fA^p@j@z@~E`FbBpBxDfFXh@|@pD`@bB^fANd@\\`Bl@rBb@fATj@v@bBjBwCd@w@NB^B\\@\\K\\Q|AWZGXOPIRBb@K\\Kl@_@VOZWVI^Eh@Ov@KxCJ\\@\\K^@RMh@QhAMXKXY`@Q^SLK`@]fBc@n@M\\OlB_@n@KNMRUZQZGh@Ht@Lx@F`@BTANDRNTPNDDHLXN`@LRTJx@?RBJFFLV\\Zs@TQ`@MVIhAYp@YPc@VgALk@Hk@d@eA\\cAHq@Eo@J}@@q@DItAgAv@i@|@e@v@k@bAaAdDuB|@c@?I?]?{@Ms@COFWJODYEcABOTU^e@H_@Km@Ci@BU?e@Ca@Ie@e@oBKk@Eu@M{@CoAC}@Km@Iy@IaA?{@Ci@Ms@UgA]y@Mm@GQICe@QKMGi@Gi@GSI[Ym@[{@@_AK]SMo@i@OCg@EOEMMYSi@IUO]Ko@KSIWUWMU_@I]Kw@WoACY@a@CWQWe@[QIOYMYW]SMQUQu@OWWSUWU[SsAEg@Ic@Mc@?a@Ai@Em@AUOa@M_@e@g@MSGYOY_@YIQSR[Pa@mBQaAI[@QDyACq@Iu@o@k@e@Y]IcAAmBC]Ee@IgAUWAw@Ae@GWSaAeAYk@Si@a@k@YAc@O{@]a@MnAqA~@mCVaAHk@YmCIQSQOS')
>>> l[:5]
[(19.52691, 73.17778), (19.52664, 73.1779), (19.52663, 73.17786), (19.52662, 73.17784), (19.5265, 73.1779)]
>>> len(l)
293

As you can see, it has 293 points. Next I tried this utility:

enter image description here

When I copy pasted that latlong array in jsoneditor, I realized that it resulted in set of 299 lat-long points.

So to find why polyline found only 293 points, I checked polyline's github page. I found that we cab pass precision parameter to decode(). But varying different values for this parameters still gave 293 points.

So now I am guessing which one is correct, online utility or polyline package?

Also is there any other official or known to be correct Python package for polyline decoding?

4
  • Check also this : stackoverflow.com/questions/15924834/… Commented Jan 17, 2022 at 11:08
  • @Taras But as I said, I want it in python and the link you shared is I guess in Java or Kotlin? Commented Jan 17, 2022 at 15:46
  • 1
    Here is a great Python implementation I use a lot myself: stackoverflow.com/a/33557535/8947209. I can tell from my experience that the result from this implementation is correct. At least I had 0 issues in hundred of tests. Commented Jan 17, 2022 at 19:56
  • @MrXsquared thanks, can you also tell how (in which format) we can store polyline in postgres so that QGIS can correctly render it? Can you please share any link discussing the same? Commented Jan 17, 2022 at 20:00

1 Answer 1

1

I found up your mistake. you forgot to add r to the string s.t it won't consider special string combinations. (i.e: r"")

if you'll define the str this way, you'll have 299 points this way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.