代码之家  ›  专栏  ›  技术社区  ›  crooksey

带有编码折线的Google静态地图API

  •  5
  • crooksey  · 技术社区  · 10 年前

    我向google directions API发出了请求,并收到了以下JSON指示:

    (文件要复制到此处) https://gist.githubusercontent.com/crooksey/9930819/raw/947e4d17a93ca94b78216d92fbd94b281966dede/directions_api

    在底部,我得到编码的多段线数据:

    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
    

    现在理论上我应该能够在地图上显示这条路线,就像。。

    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
    

    但是,唉,这行不通,有人知道为什么吗?这应该是一个相当基本的练习。因为它只是使用谷歌自己的API。

    1 回复  |  直到 10 年前
        1
  •  10
  •   crooksey    10 年前

    多段线概述似乎使用了大量“\\”,这导致了问题,因此我将“\\”的所有实例替换为“\\”。

    在字符串上使用python替换对其进行排序。

    string_new = string.replace("\\\\", "\\")