-1

I tried to send a GET request to

https://maps.googleapis.com/maps/api/staticmap?key=***&center=443.665751,-79.403373&zoom=12&size=800x600&path=color:0xFF0000AA|weight:1|fillcolor:0xFFB6C1BB|enc:...  

which the entire URL size is 272532 bytes. But when I send this request, I get Error 413 (Request Entity Too Large) error with this message:

Your client issued a request that was too large.

Is there any way to send large requests (when the path parameter is very long) to Google Maps Static API?

applesomthing
  • 361
  • 3
  • 19
Alireza Beitari
  • 436
  • 4
  • 15

1 Answers1

0

You can use Encoded Polyline as path parameter in URL request. You can encode polyline via encode() method of PolyUtil class of Maps SDK Utility Library. Also you can reduce number of points in path via simplify() method of PolyUtil class (it implements Ramer–Douglas–Peucker algorithm). So "maximum compression" for path is:

  1. reduce number of points in path using simplify();

  2. reduce length of path parameter of URL request using encode().

Also, you can create several requests with path parts and "merge" response images (as bitmaps) to create full path (e.g. this way).

Andrii Omelchenko
  • 13,183
  • 12
  • 43
  • 79
  • 1
    The Javascript API has encoding capabilities via the [Geometry library](https://developers.google.com/maps/documentation/javascript/reference/geometry#encoding). – MrUpsidown Jul 20 '21 at 08:22
  • @MrUpsidown You are right. Also both algorithms can be implemented manually. – Andrii Omelchenko Jul 20 '21 at 08:25
  • Yes, I just didn't get why you linked to the Android SDK since the question didn't mention Android but the JS API tag. – MrUpsidown Jul 20 '21 at 08:30
  • 1
    @MrUpsidown It's just because probably initially the questions was tagged by `[android]` tag. But seems answer can be applied in any platform. – Andrii Omelchenko Jul 20 '21 at 10:18
  • @AndriiOmelchenko I am already using the encode method as you can see the `enc:` parameter in `path`, but still the request is so large that Google doesn't allow it. Also I tried the `simplify` method as well but it didn't reduce the points much and I still have the original problem! – Alireza Beitari Jul 23 '21 at 13:37
  • @hhhal So use p.3: split request to several parts and merge bitmaps. – Andrii Omelchenko Jul 23 '21 at 20:30