我正在尝试生成一个静态的google地图,上面有一些点,还有一些连接这些点的线(我很快会使这些线与驾驶方向相对应,但这将在稍后进行)。现在我有这样的代码来生成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/api/maps/documentation/staticmaps/#path),我看不出哪里出错了。看看这些例子,我的URL似乎与这些例子的格式完全相同。有人知道我做错了什么吗?
谢谢
本
路径的颜色参数有问题。以下URI对我有效:
^{}
我看到默认的蓝线。
更新:错误之处在于路径颜色和路径权重之间的分隔符是pipe symbol,而不是与号。这:
^{}
工作并给出红线。
相关问题 更多 >
编程相关推荐