我試圖從Google的Direction API使用編碼折線並將其顯示在Google靜態地圖圖像中。當我在靜態貼圖中使用編碼折線時,路徑顯示不正確 - 它從正確的位置開始,並具有正確的常規路徑,但偏離預期的結果。在靜態地圖中使用來自Google Directions API的編碼折線的錯誤路徑
作爲一個例子,我已經提出了從伯爾尼到蘇黎世機場的rail
方向的請求。該API返回以下編碼折線:
}sp}[email protected]@wIiAaB_BaA}IcCmLoFqG_DuFkAyN[mEiBqN}MqFsLqUoxAyG{`@[email protected]{OfCwH[oGwAwI{EyOiTcS{[email protected]@[email protected]@iKg[aPg[_N_RiE{EoUaR{[email protected]}X}[email protected][mN}]_KqYcDePyCcQaGeUuM{[email protected]{Ka[[email protected]{S}RaS_XkRiX{OiO{[email protected]@{[email protected]{[email protected][email protected]@qTcZmNyZkUcRkSsIiL{Qq[qHuPuLk]wIe][email protected]\\[email protected]`[email protected]`AazA}JgR{[email protected]}Gg\\[email protected]@[email protected]_sCyT_~AsVuwAkGaT}[email protected]@y{@{[email protected]@kQcQ}MwPoQu[{[email protected]_Gm[[email protected]\\iPkTi[cYuOyIqQsGcYuFm][email protected]@cU{G}IaGeHcH}IsMyFaMsKi]eLw`@[email protected]@[email protected][email protected]{W}DmOkFcXiQ{WgTkLgL}[email protected]}[email protected]~BmNdR{[email protected][email protected]@vA}JfEeNvH{T|AcKXyN{AgQeDeNeHqWwYseAcX_eA}IwSqGiHsHeE{[email protected]{H_EuLyWg|@wX{[email protected]_[klB_Q{iAgRegCkTsqCmK{[email protected][|E}[email protected]`[email protected]@bBcPaAmX_ByRcJmgAsCa]yEaTuFqJsG{[email protected]}P}JoIsJmQuKoRgFgLgCuJaTghAwI}`@cJsVgIsMgZ{XkH{[email protected]}`AylKyBeWEsLrAiTfB}LzS{[email protected]|[email protected]@[email protected]@dGkOhO{\\rE_FtJgPv[[email protected]~EeG`HoK|LmH~SuJjGqEbHuN|[email protected]@bAyQYmP}B{[email protected]@[email protected]|[email protected]_SLyNpD_\\~DuXbJq`@zDySbDqJrM{[email protected]}[email protected]@[email protected]`[email protected]~BsCbNyBdLsAzHOzOaAlKaDhGiEzBoFOiDgCgD{HiEoPcG_HiVaLiF_CwIwFgFaBiOkFoQgIe[iNsJyF}[email protected]`@[email protected]}CVcEtAaE|[email protected]
繪製使用谷歌地圖API的結果在正確的路徑此編碼折線:
function initialize() {
var map = new google.maps.Map(document.getElementById('map-canvas'), {
center: {
lat: 47.23,
lng: 8.00
},
zoom: 09
});
var encoded_data = '}sp}[email protected]@wIiAaB_BaA}IcCmLoFqG_DuFkAyN[mEiBqN}MqFsLqUoxAyG{`@[email protected]@wH[oGwAwI{EwFqGaHwKcS{[email protected]@[email protected]@iKg[aPg[_N_RiE{EoUaR{[email protected]}X}[email protected][mN}]_KqYcDePyCcQaGeUuM{[email protected]{Ka[[email protected]{S}RaS_XkRiX{OiO{[email protected]@{[email protected]{[email protected][email protected]@qTcZmNyZkUcRkSsIiL{Qq[qHuPuLk]wIe][email protected]\\[email protected]`AiRm^[email protected]`AazA}JgR{[email protected]}Gg\\[email protected]@[email protected][email protected]@kGaT}[email protected]@y{@{[email protected]@kQcQ}MwPoQu[{[email protected]_Gm[[email protected]\\iPkTi[cYuOyIqQsGcYuFm][email protected]@cU{G}IaGeHcH}IsMyFaMsKi]eLw`@[email protected]@[email protected][email protected]{W}DmOkFcJ}E_MkJ{WgTkLgL}[email protected]}[email protected]~BmNdR{[email protected][email protected]@vA}JfEeNpG_Q|[email protected]{[email protected]@i|AyJc^[email protected]}[email protected]__B}[email protected]{Q{fAg\\[email protected]_SFeNjCwWhI_W`MaRjFgLbVueAdHa[fP}[email protected]_BoVoHi}@{Hq{@yF}QyFaImH_FaQqGmQcJqH}[email protected]{FyZcVcmAeJ_W{LcRqOaNgK{KeI{PeFoW}@[email protected]@[email protected]@[email protected]{|[email protected]@[email protected]@tVu|@zF}PhN}\\rDoH~BaCvDqEn][email protected][email protected]@ViQ}@qS{[email protected]{@o[\\yV`N{[email protected]~W{[email protected]}IpCwQbIe`@[email protected]_PvFkT~CgMdAaGeA`[email protected]`SG|OsAlKaDlF{[email protected]}CoCaDcI{EcQ}F{[email protected][email protected]@[email protected][email protected]_AcNsGuF}J';
var decode = google.maps.geometry.encoding.decodePath(encoded_data);
var line = new google.maps.Polyline({
path: decode,
strokeColor: '#red',
strokeOpacity: 1.0,
strokeWeight: 4,
zIndex: 3
});
line.setMap(map);
}
initialize();
#map-canvas {
height: 400px;
}
<script src="https://maps.googleapis.com/maps/api/js?libraries=geometry&sensor=false"></script>
<div id="map-canvas"></div>
然而,當在靜態地圖中使用相同的編碼多段線時,路徑從伯爾尼開始並結束f在蘇黎世北部。這裏的靜態URL:
https://maps.googleapis.com/maps/api/staticmap?size=512x512&scale=2&maptype=terrain&style=feature:all&path=weight:3%7Ccolor:0xff0000ff%7Cgeodesic:true%7Cenc:} SP} Gmrkl @米@ wIiAaB_BaA} IcCmLoFqG_DuFkAyN [mEiBqN} MqFsLqUoxAyG {@[email protected]@wH[oGwAwI{EwFqGaHwKcS{[email protected]@[email protected]@iKg[aPg[_N_RiE{EoUaR{[email protected]}X}[email protected][mN}]_KqYcDePyCcQaGeUuM{[email protected]{Ka[[email protected]{S}RaS_XkRiX{OiO{[email protected]@{[email protected]{[email protected][email protected]@qTcZmNyZkUcRkSsIiL{Qq[qHuPuLk]wIe][email protected]\\[email protected]
AIRM^oXwe @üAazA}JgR{[email protected]}Gg\\[email protected]@[email protected][email protected]@kGaT}[email protected]@y{@{[email protected]@kQcQ}MwPoQu[{[email protected]_Gm[[email protected]\\iPkTi[cYuOyIqQsGcYuFm][email protected]@cU{G}IaGeHcH}IsMyFaMsKi]eLw
@ qKab @ kIwe @ eDkLyKwRiGsFoOuGcGkAuQm @ uH容_ @【W】DmOkFcJ} E_MkJ {WgTkLgL } I_KwJgGcHoBeGMaIjBuDhA_GRab @ aEoKuCqFaEoIsQaG} NkDuL_ @ QR〜BmNdR {b @ zEaW〜東歐@ vEsv @ vA型} JfEeNpG_Q | A_HfAwOq @ QQ {DeRgSou @ EB @ I | AyJc^aKcOeHyEm_ @ aNeOsFkDiCmEaGiIiV}ë@__ b} KKC @ {Q {FAG \ wpBkLqrAeWuiDyUuwCqGak @ aA_SFeNjCwWhI_W MaRjFgLbVueAdHa[fP}[email protected]_BoVoHi}@{Hq{@yF}QyFaImH_FaQqGmQcJqH}[email protected]{FyZcVcmAeJ_W{LcRqOaNgK{KeI{PeFoW}@[email protected]@[email protected]@[email protected]{|[email protected]@[email protected]@tVu|@zF}PhN}\\rDoH~BaCvDqEn][email protected][email protected]@ViQ}@qS{[email protected]{@o[\\yV
N {噸@〜W {zAdVowAZeNvA_MbEmTxHeZb @} IpCwQbIe @[email protected]_PvFkT~CgMdAaGeA
的Gq @ xDkAhEaBdHsBvIcE`SG | OsAlKaDlF {ErBgFg @} CoCaDcI {ECQ} F到{FcHaDiNiGwGoDwGgEgOkEca @ mQmVaLyFgEcIiOaG_QiDuLsBuCuJkIgWsT_m @ UJ @ iPgNqSaEoKc @ cBRgFpB_DdCqMjHyJxCsJv @ aW_AcNsGuF}Ĵ
併產生圖像:
我曾嘗試geodesic
PARAM設置爲true
和false
但似乎沒有什麼區別。
可以在靜態地圖中使用來自Google Directions的編碼多段線嗎?如果是這樣,需要哪些參數才能正確顯示它們?
明白了。因此Directions API使用'\\',對於靜態地圖URL,'\\'應該用'\'替換。 –