0

This works fine:

static void Main(string[] args)
{
    string latlng = "55.379110,-3.1420898";
    string url = "http://maps.googleapis.com/maps/api/staticmap?center=" + latlng +
       "&zoom=6&size=1000x1000&maptype=satellite&markers=color:blue%7Clabel:S%7C" +
       latlng + "&sensor=false";

    using (WebClient wc = new WebClient())
    {
    wc.DownloadFile(url, @"C:\Bla\img.png");
    }
}

Just wondering, how could I add hundreds of pins and save the map as a png? Surely there is a limit for get request and one can not append too many query string parameters.

PS: The limit is 8192 characters - see https://developers.google.com/maps/documentation/static-maps/intro section URL Size Restriction

xomena
  • 31,125
  • 6
  • 88
  • 117
cs0815
  • 16,751
  • 45
  • 136
  • 299

3 Answers3

2

I'm afraid downloading and storing static maps images is against ToS:

You may not store and serve copies of images generated using the Google Static Maps API from your website. All web pages that require static images must link the src attribute of an HTML img tag or the CSS background-image attribute of an HTML div tag directly to the Google Static Maps API so that all map images are displayed within the HTML content of the web page and served directly to end users by Google.

https://developers.google.com/maps/faq?csw=1#tos_staticmaps_reuse

xomena
  • 31,125
  • 6
  • 88
  • 117
1

You will have to deal with an url size restriction from Google Map Static API. https://developers.google.com/maps/documentation/static-maps/intro#url-size-restriction

URL Size Restriction Google Static Maps API URLs are restricted to 8192 characters in size. In practice, you will probably not have need for URLs longer than this, unless you produce complicated maps with a high number of markers and paths. Note, however, that certain characters may be URL-encoded by browsers and/or services before sending them off to the API, resulting in increased character usage. For more information, see Building a Valid URL.


To Add multiple marker:

https://developers.google.com/maps/documentation/static-maps/intro

https://maps.googleapis.com/maps/api/staticmap?center=Brooklyn+Bridge,New+York,NY&zoom=13&size=600x300&maptype=roadmap&markers=color:blue%7Clabel:S%7C40.702147,-74.015794&markers=color:green%7Clabel:G%7C40.711614,-74.012318&markers=color:red%7Clabel:C%7C40.718217,-73.998284&key=YOUR_API_KEY
Yanga
  • 2,885
  • 1
  • 29
  • 32
0

You may also be interested in: Issue 207: KML layer in Static Maps API

miguev
  • 4,481
  • 21
  • 41