Google Static Maps API with encoded polyline

会有一股神秘感。 提交于 2019-12-06 02:51:05

问题


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.


回答1:


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("\\\\", "\\")


来源:https://stackoverflow.com/questions/22839246/google-static-maps-api-with-encoded-polyline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!