Google Static Maps API:生成带有路径的静态地图
我正在尝试生成一个静态谷歌地图,上面有一些点,以及一些连接这些点的线(我很快就会使这些线与行车方向相对应,但稍后会出现)。现在我有这样的代码来生成 URL:
def getStaticMapAddress(self, route):
url = "http://maps.google.com/maps/api/staticmap?center="+str(route[0].location.lat)+","+str(route[0].location.lng)+"&zoom=6&size=400x400&markers="
i=0
while i<len(route):
url += str(route[i].location.lat)+","+str(route[i].location.lng)
i=i+1
if (i < len(route)):
url += "|"
url += "&path=color:0xff0000ff&weight:5"
i=0
while i<len(route):
url += "|"+str(route[i].location.lat)+","+str(route[i].location.lng)
i+=1
url += "&sensor=false"
return url
在这个函数中,“路线”是具有关联位置的用户列表。根据我的测试数据,生成了以下 URL:
http://maps.google.com/maps/api/staticmap?center=50.8202008,-0.1324898&zoom=6&size=400x400&markers=50.8202008,-0.1324898|51.447341,-0.0761212|51.4608947,-2.5884312&path=color:0xff0000ff&weight:5|50.8202008,-0.1324898|51.447341,-0.0761212|51.4608947,-2.5884312&sensor=false
如果您查看该静态地图,您可以看到标记,但看不到路径。我一直在查看这方面的文档(http://code.google.com/apis/maps/documentation/staticmaps/#Paths),但我看不出哪里出了问题。查看示例,我的 URL 似乎与示例具有完全相同的格式。有谁知道我做错了什么?
谢谢
本
I'm trying to generate a static google map with some points on it, and some lines connecting these points (I'm soon going to make the lines correspond with the driving directions, but that comes later). Right now I've got code like this to generate the URL:
def getStaticMapAddress(self, route):
url = "http://maps.google.com/maps/api/staticmap?center="+str(route[0].location.lat)+","+str(route[0].location.lng)+"&zoom=6&size=400x400&markers="
i=0
while i<len(route):
url += str(route[i].location.lat)+","+str(route[i].location.lng)
i=i+1
if (i < len(route)):
url += "|"
url += "&path=color:0xff0000ff&weight:5"
i=0
while i<len(route):
url += "|"+str(route[i].location.lat)+","+str(route[i].location.lng)
i+=1
url += "&sensor=false"
return url
In this function, the 'route' is a list of users with associated locations. With my test data, this URL was generated:
http://maps.google.com/maps/api/staticmap?center=50.8202008,-0.1324898&zoom=6&size=400x400&markers=50.8202008,-0.1324898|51.447341,-0.0761212|51.4608947,-2.5884312&path=color:0xff0000ff&weight:5|50.8202008,-0.1324898|51.447341,-0.0761212|51.4608947,-2.5884312&sensor=false
If you look at that static map, you can see the markers but not the paths. I've been looking at the documentation for this (http://code.google.com/apis/maps/documentation/staticmaps/#Paths) and I can't see where I've gone wrong. Looking at the examples my URL seems to have the exact same format as the examples. Does anyone know what I'm doing wrong?
Thanks
Ben
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
路径的颜色参数有问题。以下 URI 适用于我:
http:// /maps.google.com/maps/api/staticmap?center=50.8202008,-0.1324898&zoom=6&size=400x400&markers=50.8202008,-0.1324898|51.447341,-0.0761212|51.4608947,-2.58 84312&路径=权重:5|50.8202008,-0.1324898|51.447341,-0.0761212|51.4608947,-2.5884312&sensor=false
我看到默认的蓝线。
更新:“错误”是路径颜色和路径粗细之间的分隔符是 管道符号,而不是 & 符号。这个:
http:// maps.google.com/maps/api/staticmap?center=50.8202008,-0.1324898&zoom=6&size=400x400&markers=50.8202008,-0.1324898|51.447341,-0.0761212|51.4608947,-2.588第4312章0xff0000ff|weight:5|50.8202008,-0.1324898|51.447341,-0.0761212|51.4608947,-2.5884312&sensor=false
有效并给出一条红线。
There is something wrong with the color parameter of the paths. The following URI works for me:
http://maps.google.com/maps/api/staticmap?center=50.8202008,-0.1324898&zoom=6&size=400x400&markers=50.8202008,-0.1324898|51.447341,-0.0761212|51.4608947,-2.5884312&path=weight:5|50.8202008,-0.1324898|51.447341,-0.0761212|51.4608947,-2.5884312&sensor=false
and I see the default blue lines.
Update: the "something wrong" is that the separator between the path color and path weight is a pipe symbol, not an ampersand. This:
http://maps.google.com/maps/api/staticmap?center=50.8202008,-0.1324898&zoom=6&size=400x400&markers=50.8202008,-0.1324898|51.447341,-0.0761212|51.4608947,-2.5884312&path=color:0xff0000ff|weight:5|50.8202008,-0.1324898|51.447341,-0.0761212|51.4608947,-2.5884312&sensor=false
works and gives a red line.