5

I have made a request to google directions API and recived the following JSON directions:

(file to large to copy here) https://gist.githubusercontent.com/crooksey/9930819/raw/947e4d17a93ca94b78216d92fbd94b281966dede/directions_api

At the bottom, I get the encoded polyline data:

ecduHxqrE|RfS{SlW_w@zDc{@ig@cVlK}z@j}Aog@z{AuGbdDibAfkGaBpcG}~@vrGy_AhhCoi@feB{bBxu@kxAsSus@|eAcLdyBci@dcByi@ly@`GrgC_S~d@e\\wBugA_uBwuAusAoaCidAs~Dq{DiaAu`CuwAweAevBi@}dDwgCsrAwfBuqFkmBwzEu~DenAa|Bi_BcuDmrAghF_{B_hGa{@chAocAl[m_@pXwk@{z@}Zc~A_hAmn@mdAinBg_@eD{o@moA{_@kz@sn@ca@oWmcCoQsUue@`De{@yH{oA~i@meAliA}wAa]ij@qg@}o@w_@yVrT_k@|Y{oCi`@e_@RqEjOvUx\\`TjDv@yi@ttA~Gr}@`Fxi@ad@v]yJ|gAxlAjsAz_@|l@oYzbBatAn_CdJdSv_B~f@rlAhk@`j@f_@`rAhpAfs@f`@`kAfg@`Nr_AbgBtNt~@nb@vRlc@gXry@}Wd^iIdv@zfCvgCj{GlcAzxEnkDfkGlgGtpE|eEf{AvzBx{BzvA|_B~\\yAjyBxJzwA|wA~_AznBlgAt_AbhBpsB`xChzAxsA|uAxVnxBnPb}AzCx`EnhA`qDwCnpG~SvrCbmA|lCd{B~jFdZzbCn{@b`EhqA|aBb_Ad}BdkBxjEx[vgC|HluEfUnkBtfB`eF~mAzjD`V~q@y_@pnEtv@byChn@tv@`dBjoFz_@KdbElc@f]|My@bc@da@mKptA`Nhj@aq@fHlAbK~M?Z_UyOw^ji@su@Ju|@`qEX`cBnw@|lAsRjlD_q@~nHgA`vH}m@hvEs]gL~AzkCt[hiCcJlvFuAzzE`a@jbDnlBxyG||C|~B`d@juCaiAf`DoQf`HhS|jBLpmBuLd`Dma@zsBc[ftGcx@t|H{TnyGxTzdA_Bn[kPysBhZm`HvvAk`Rdb@ehBoBypCdF}hB_YgcAzMqx@nEohGriAi~Ca_@mpCopCkoBwpC_iIaKegKlIu{EuX_{CgD{pBs^oXuu@kpEqZmzDymBmwDt`@qkEhEmzCjCiyBqSonCmKm|@rRweC{R}cBw{@{fDeo@}u@q|@g}Cx_@quEqdBcyEs}Ba_HoQ{dJysDyvIiiBejDup@e{D{mAuxDes@a_BcoBkdGgEweJp|AkTl{@u_@lg@_{Afp@suDzBmgAmLyp@qw@sx@wdAafA_~BukA`bAmeBfl@orEtn@}f@xkAbVptAgk@xv@{}A|p@cyAhjAsiHpEkyFbaAceHvLe~Dli@a~Ary@eeBx}@lUbb@jVzf@_NhKs^yH{I

Now In theory I should be able to display this route on a map, as easy as..

https://maps.googleapis.com/maps/api/staticmap?size=400x400&path=weight:10%7Ccolor:orange%7Cenc:ecduHxqrE|RfS{SlW_w@zDc{@ig@cVlK}z@j}Aog@z{AuGbdDibAfkGaBpcG}~@vrGy_AhhCoi@feB{bBxu@kxAsSus@|eAcLdyBci@dcByi@ly@`GrgC_S~d@e\\wBugA_uBwuAusAoaCidAs~Dq{DiaAu`CuwAweAevBi@}dDwgCsrAwfBuqFkmBwzEu~DenAa|Bi_BcuDmrAghF_{B_hGa{@chAocAl[m_@pXwk@{z@}Zc~A_hAmn@mdAinBg_@eD{o@moA{_@kz@sn@ca@oWmcCoQsUue@`De{@yH{oA~i@meAliA}wAa]ij@qg@}o@w_@yVrT_k@|Y{oCi`@e_@RqEjOvUx\\`TjDv@yi@ttA~Gr}@`Fxi@ad@v]yJ|gAxlAjsAz_@|l@oYzbBatAn_CdJdSv_B~f@rlAhk@`j@f_@`rAhpAfs@f`@`kAfg@`Nr_AbgBtNt~@nb@vRlc@gXry@}Wd^iIdv@zfCvgCj{GlcAzxEnkDfkGlgGtpE|eEf{AvzBx{BzvA|_B~\\yAjyBxJzwA|wA~_AznBlgAt_AbhBpsB`xChzAxsA|uAxVnxBnPb}AzCx`EnhA`qDwCnpG~SvrCbmA|lCd{B~jFdZzbCn{@b`EhqA|aBb_Ad}BdkBxjEx[vgC|HluEfUnkBtfB`eF~mAzjD`V~q@y_@pnEtv@byChn@tv@`dBjoFz_@KdbElc@f]|My@bc@da@mKptA`Nhj@aq@fHlAbK~M?Z_UyOw^ji@su@Ju|@`qEX`cBnw@|lAsRjlD_q@~nHgA`vH}m@hvEs]gL~AzkCt[hiCcJlvFuAzzE`a@jbDnlBxyG||C|~B`d@juCaiAf`DoQf`HhS|jBLpmBuLd`Dma@zsBc[ftGcx@t|H{TnyGxTzdA_Bn[kPysBhZm`HvvAk`Rdb@ehBoBypCdF}hB_YgcAzMqx@nEohGriAi~Ca_@mpCopCkoBwpC_iIaKegKlIu{EuX_{CgD{pBs^oXuu@kpEqZmzDymBmwDt`@qkEhEmzCjCiyBqSonCmKm|@rRweC{R}cBw{@{fDeo@}u@q|@g}Cx_@quEqdBcyEs}Ba_HoQ{dJysDyvIiiBejDup@e{D{mAuxDes@a_BcoBkdGgEweJp|AkTl{@u_@lg@_{Afp@suDzBmgAmLyp@qw@sx@wdAafA_~BukA`bAmeBfl@orEtn@}f@xkAbVptAgk@xv@{}A|p@cyAhjAsiHpEkyFbaAceHvLe~Dli@a~Ary@eeBx}@lUbb@jVzf@_NhKs^yH{I&sensor=true

But alas, this does not work, anyone have any ideas as to why? It should be a fairly basic exercise. As it's just using googles own API.

crooksey
  • 8,521
  • 6
  • 30
  • 52
  • Well that's a good question and I can't figure out why this doesn't work :( – MrUpsidown Apr 03 '14 at 14:09
  • I'm not sure if URL size limit is reached. Using just the first 8 points I got map of Portsmouth harbour with polyline. In that case URL was very short comparing to original one. – Anto Jurković Apr 03 '14 at 14:13
  • No its not the size limit, as I can increase it with random locations and it reaches the size length. But not as it is. – crooksey Apr 03 '14 at 14:15
  • Right. This URL is around 1300 characters. I think under 2000, you should be good to go. And yes, removing a few points at the end gives you the map and polyline. – MrUpsidown Apr 03 '14 at 14:51
  • How can I trim this consistently in a production environment then? Can you post the working URL? – crooksey Apr 03 '14 at 14:55
  • Well the thing is that you should not need to trim it... That one works: http://goo.gl/6YJ1pY – MrUpsidown Apr 03 '14 at 14:59
  • possible duplicate of [Directions API overview\_polyline doesn't have correct points](http://stackoverflow.com/questions/13360928/directions-api-overview-polyline-doesnt-have-correct-points) – Anto Jurković Apr 03 '14 at 15:01
  • Removing one '\' from '...\\wBugA' it seems produce whole polyline. Otherwise it breaks with 96 coordinate points. – Anto Jurković Apr 03 '14 at 15:04
  • 1
    @AntoJurković That's right. It works, but it doesn't seem to be the same route at all if you compare to my trimmed URL. Strange. I double checked the doc and it clearly states that URLs should be under 2048 characters, which is the case here. And removing all double backslashes gives me yet another route. – MrUpsidown Apr 03 '14 at 15:13
  • Do you get the expected route using https://developers.google.com/maps/documentation/utilities/polylineutility ? – MrUpsidown Apr 03 '14 at 15:21
  • No, the route is completely wrong. – crooksey Apr 03 '14 at 15:32
  • Removing the "/" like you said works: http://goo.gl/pKzlGB – crooksey Apr 03 '14 at 15:33

1 Answers1

10

It seems the polyline overview used a lot of "\\" which causes the problem, so I replaced all instance of "\\" with "\".

Used python replace on the string to sort it.

string_new = string.replace("\\\\", "\\")
crooksey
  • 8,521
  • 6
  • 30
  • 52