4

I generate URL for calling Google Static Map API but in sometime my url is very long (>2048). How can I solved this ?

Kara
  • 6,115
  • 16
  • 50
  • 57
cloverink
  • 588
  • 8
  • 23

4 Answers4

6

You can encode your Polylines and make them shorter .

Here is the example which can help you how to short your Polylines

I am using the php library to short the length here is the link of library https://github.com/danmandle/encoded-polyline-stitcher

if you use this library

(51.838245,-111.834991|51.833179,-111.83503|51.831007022306,-111.8232751234|51.838244686875,-111.82327418214)  =  (atk{HtwqiTt^FpLmhAgl@)

Here important point is if you use short url you have to use "enc:" keyword

(fillcolor:0xAA000033|color:0xFFFFFF00|51.838245,-111.834991|51.833179,-111.83503|51.831007022306,-111.8232751234|51.838244686875,-111.82327418214)  =   (fillcolor:0xAA000033|color:0xFFFFFF00|enc:atk{HtwqiTt^FpLmhAgl@)

The Library is available for other languages as well if you are not using php .

I hope that it helps others

veljasije
  • 6,722
  • 12
  • 48
  • 79
Mehran Khan
  • 3,616
  • 1
  • 13
  • 10
  • using encoding we lose precision so if you need precision for more than 5 decimal places then encoding will not work for you. As we totally lose the shape with encoded path – rohan dani Feb 22 '19 at 04:16
3

If your url includes polylines you can encode them and make them much shorter. Here's Google's explanation of it, you'll then need to look around for an implementation in whatever language you're using.

https://developers.google.com/maps/documentation/utilities/polylineutility

Craig
  • 8,093
  • 8
  • 42
  • 74
2

Recently, in August 2016, the URL limit has been changed to 8192 characters in size.

https://developers.google.com/maps/documentation/static-maps/intro#url-size-restriction

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

You cannot do anything if the URL is too long. It is by design of the web browser.

See this question limitation of url

If static maps API isn't helping you to achieve your task, you might want to take a look @ other Google Maps APIs

Community
  • 1
  • 1
Ranhiru Jude Cooray
  • 19,542
  • 20
  • 83
  • 128