简体   繁体   English

Google Static Maps API:生成包含路径的静态地图

[英]Google Static Maps API: Generating a static map with paths

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: 现在我有这样的代码来生成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: 使用我的测试数据,生成了以下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

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. 我一直在查看这方面的文档(http://code.google.com/apis/maps/documentation/staticmaps/#Paths),我看不出哪里出错了。 Looking at the examples my URL seems to have the exact same format as the examples. 查看示例,我的URL似乎与示例具有完全相同的格式。 Does anyone know what I'm doing wrong? 有谁知道我做错了什么?

Thanks 谢谢

Ben

There is something wrong with the color parameter of the paths. 路径的颜色参数有问题。 The following URI works for me: 以下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.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. 工作并给出一条红线。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM