我正在尝试生成一个静态的谷歌地图,上面有一些点,并且这些点之间有一些相互连接的线(我很快就会让这些线对应着驾车路线,但那是后话)。现在,我已经有了以下代码来生成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
在这个函数中,“route”是一个用户列表,其中包含关联的位置信息。使用我的测试数据,生成了以下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似乎与示例具有完全相同的格式。有人知道我做错了什么吗?
谢谢。 Ben