0

我正在尝试从谷歌地图静态图像 API 获取远足小径的静态图像,但我看到了一些奇怪的行为。有时,它工作得很好,而其他时候,它要么根本不显示路径,要么以一种奇怪的方式渲染它。

这是一个没有按照我期望的方式显示的路径示例:锯齿状路径

当我从这些相同的坐标构建 KML 时,一切都以我期望的方式显示。但是当它被发送到静态图像 API 时,事情就变得混乱了。

我一直在调整地图的中心和缩放,但没有明显的效果。为了适应 URL 字符限制,我不得不减少路径中的坐标数。我尝试调整路径中的点数,但我仍然得到一个奇怪的锯齿状路径,而不是我从 KML 文件中看到的路径。

我还尝试从上面的 URL 中删除坐标,直到找到罪魁祸首,但后来我遇到了另一个问题。试试这个图像:没有任何积分。您会注意到此图像中根本没有显示路径。

有时,调用工作得很好(我没有得到我想要的粒度,因为我必须在 URL 长度限制内修剪坐标 - 但我可以忍受)。你可以在这里看到一个例子:工作示例

这是怎么回事?我是否犯了一些我看不到的简单错误,或者这是谷歌的结果?谢谢!

4

1 回答 1

0

我想到了。我没有正确转义 URL。我浏览 API 站点的速度太快了(在此处找到),当我返回并再次查看指南时,我注意到了一些我第一次错过的东西。我正在使用python url转义函数,它没有转义需要转义的部分和转义不需要转义的东西。

这是工作路径的示例:

http://maps.googleapis.com/maps/api/staticmap?format=jpg-baseline&maptype=terrain&size=320x320&sensor=true&path=color:0xff0000ff%7Cweight:2%7C34.680923,-83.998035%7C34.682763,-83.996703% 7C34.684612,-83.995759%7C34.685855,-83.994969%7C34.687478,-83.993794%7C34.689339,-83.99301%7C34.691484,-83.992649%7C34.693114,-83.991636%7C34.695631,-83.991983%7C34 .697488,-83.990639%7C34.698856,-83.988732%7C34.700114,-83.986356%7C34.701881,-83.985913%7C34.703546,-83.98486%7C34.705588,-83.984205%7C34.707439,-83.985204%7C34. 709409,-83.98474%7C34.710815,-83.982891%7C34.713098,-83.982932%7C34.715471,-83.983.981058%7C34.715642,715643, -83.97896%717896%and-83.97896%and-83.97896%and-83.97896% ,-83.97285%7C34.720504,-83.972258%7C34.722156,-83.970446%7c34.723245,-83.970965% -83。962787%7C34.730165,-83.960224%7C34.730464,-83.957465%7C34.731384,-83.954936%7C34.733571,-83.952937%7C34.735248,-83.951872%7C34.736235,-83.94911%7C34.738577,-83.94717 %7C34.740465,-83.946156%7C34.741132,-83.943978%7C34.743225,-83.944512%7C34.745393,-83.943994%7C34.742783,-83.942916%7C34.742451,-83.941822%7C34.741552,-83.940703% 7C34.740811,-83.939462%7C34.74023,-83.937804%7C34.738605,-83.936371%7C34.736056,-83.935923% .738196,-83.931812%7C34.737864,-83.9307%7C34.735883,-83.930629%7C34.735412,-83.928034%743225,-83.944512%7C34.745393,-83.943994%7C34.742783,-83.942916%7C34.742451,-83.941822%7C34.741552,-83.940703%7C34.740811,-83.939462%7C34.74023,-83.937804%7C34.738605 ,-83.936371%7C34.736056,-83.935923%7C34.734862,-83.935931%7C34.736535,-83.93444335% -83.930629%7C34.735412,-83.928034%7C34.736785,-83.925242%7C34.737286,-83.922985%7C34.735846,-83.918937743225,-83.944512%7C34.745393,-83.943994%7C34.742783,-83.942916%7C34.742451,-83.941822%7C34.741552,-83.940703%7C34.740811,-83.939462%7C34.74023,-83.937804%7C34.738605 ,-83.936371%7C34.736056,-83.935923%7C34.734862,-83.935931%7C34.736535,-83.93444335% -83.930629%7C34.735412,-83.928034%7C34.736785,-83.925242%7C34.737286,-83.922985%7C34.735846,-83.918937

于 2013-01-14T15:30:15.587 回答