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.
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!