Google Static Maps API:生成带有路径的静态地图

发布于 2024-10-19 00:22:25 字数 1274 浏览 1 评论 0原文

我正在尝试生成一个静态谷歌地图,上面有一些点,以及一些连接这些点的线(我很快就会使这些线与行车方向相对应,但稍后会出现)。现在我有这样的代码来生成 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

双手揣兜 2024-10-26 00:22:25
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文