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

11,884

Solution 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

Solution 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

Share:
11,884
Kevin
Author by

Kevin

Updated on June 04, 2022

Comments

  • Kevin
    Kevin almost 2 years

    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!

  • shimatai
    shimatai about 7 years
    You must take care to treat long URL paths (current limit is 2048 bytes). If you need to use long URLs, you should use polyline encoding, as described in Google Maps Static API documentation and the algorithm format is explained in this link
  • BIS Tech
    BIS Tech about 4 years
    sensor parameter no longer required.. developers.google.com/maps/documentation/maps-static/…