How to load a static google map with a path (polyline)?

与世无争的帅哥 提交于 2020-02-28 08:13:17

问题


I have implemented some code that loads an image from a URL upon a listview item being clicked; this has been tested with a 'dummy' image and works without any problem with the image being displayed in an imageview object.

However, what I really want to do is to load a Static Google Map with Paths (polyline) via URL, but for some reason this is not working and I hope that someone here will be able to tell me what is wrong with my URL:

http://maps.googleapis.com/maps/api/staticmap?size=400x400&path=40.737102,-73.990318|40.749825,-73.987963|40.752946,-73.987384|40.755823,-73.986397

According to the Google documentation http://code.google.com/apis/maps/documentation/staticmaps/ I believe that my URL should work, because an image witha path only requires the size attribute (i.e. all others are optional).

When I try to test load my URL via a web-browser I receive an Error 403 in Google Chrome telling me that the googleapis website requires a log in. Is this the API key? I have an API key that I've previously used for a non-static google map and I copy/pasted this key from the map's xml into my URL (using the key= attribute), but again this was not successful.

I've tried searching on google and this forum, but it seems that no-one has had this problem before - or maybe I'm just really bad at searching :( But hopefully someone can assist?

Thanks!


回答1:


You're missing the required sensor parameter.

http://maps.googleapis.com/maps/api/staticmap?size=400x400&path=40.737102,-73.990318|40.749825,-73.987963|40.752946,-73.987384|40.755823,-73.986397&sensor=false



回答2:


This requirement is fairly new, but yes, you are missing the API key.

Just as you added the parameters &size= or &path=, at some point you need to have a &key=parameter. So for your example it would look like this:

http://maps.googleapis.com/maps/api/staticmap?size=400x400&key=ENTER-YOUR-API-KEY&path=40.737102,-73.990318|40.749825,-73.987963|40.752946,-73.987384|40.755823,-73.986397

hope that helps



来源:https://stackoverflow.com/questions/8874173/how-to-load-a-static-google-map-with-a-path-polyline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!