0

I need to get a static image of a map with a large number of polygons on it .

Reference is generated from the array which can be more than two thousand coordinates.

link += "&path=weight:5|fillcolor:"+color+"|"+params[i].cords[0].lat+","+params[i].cords[0].lng+"|"+params[i].cords[1].lat+","+params[i].cords[1].lng+"|"+params[i].cords[2].lat+","+params[i].cords[2].lng+"|"+params[i].cords[3].lat+","+params[i].cords[3].lng;

After this, I am assuming this URL to the 'img' element:

img.src = "https://maps.googleapis.com/maps/api/staticmap?format=jpg&zoom=2&size=400x400"+ generateParamsForLink(params) +"&key="mykey"

When a request is sent , I get an error - net::ERR_CONNECTION_CLOSED

my short url =)

I will be glad to any advice.

1 Answers1

0

You have over 16k characters in your URL. I'm afraid this API won't work the way you want it to

Here is the link to the section of the API documentation where the limit is stated to be 2048 characters: https://developers.google.com/maps/documentation/static-maps/intro#url-size-restriction

You should also url encode like so img.src = "https://maps.googleapis.com/maps/api/staticmap?format=jpg&zoom=2&size=400x400"+ encodeURIComponent(generateParamsForLink(params)) +"&key="mykey"

You also have an extra ampersand before the key in your generated version, I'm guessing that's because the last item in params in empty.

Hope this helps, sorry I don't have better news. I'd suggest using an embedded google map, but disabling interaction.

If you really need the image, here is a post that has a solution, I have not tested it and cannot vouch for how well it works. If it works for you, please let me know!

Google Maps image?

Community
  • 1
  • 1
Jim Edelstein
  • 792
  • 6
  • 10
  • Thank you, I apparently missed the information on size restrictions. I used static maps to generate pdf file . Perhaps you know how I can do without them ? – Anton Gorshenin Feb 13 '16 at 22:29
  • @AntonGorshenin I just updated the answer, please do let me know if that works for you. I have run into a similar problem in the past generating a map to embed in a PDF for print that was not high enough resolution because of the size restrictions. We ultimately decided to forgo the map at that time, but I wasn't able to find this solution back then. – Jim Edelstein Feb 14 '16 at 00:06
  • I also could not find a solution for the construction of large data through the Static API . At the same time I also tried to use OSM + mapbox + leaflet_image. This solution allows to place a string of 4096 characters. But this is unfortunately not enough for my purposes ( Now I try to use highcharts maps. – Anton Gorshenin Feb 15 '16 at 10:05
  • Good luck @AntonGorshenin! If you find a solution perhaps post it as an answer, I don't know the SO protocol when the question changes like this, but I would love to see an answer to static mapping with large datasets. – Jim Edelstein Feb 15 '16 at 10:56