0

I want to display static map in my application, when i tried to get static image by using this URL

http://maps.google.com/maps/api/staticmap?path=color:0x0000ff|weight:5|40.737102,-73.990318|40.755823,-73.986397&zoom=14&size=400x400&sensor=false

It is working fine in the browser but in my app when i use this link it results in illegal argument exception at index 61 (index 61 is the first | character).

So i have searched for this error and i found something to use like this

URL = "http://maps.google.com/maps/api/staticmap?"
+URLEncoder.encode("path=color:0x0000ff|weight:5|40.737102,-73.990318|40.755823,-73.986397&zoom=14&size=400x400&sensor=false", "UTF-8");

but it shows the URL with % in place of | and results in error

The Google Maps API server rejected your request. Invalid request. Missing the 'size' parameter.

How can i solve this issue?

Oleg Estekhin
  • 8,063
  • 5
  • 49
  • 52
Nithin
  • 503
  • 4
  • 19
  • I'd expect that the `|` symbol would be encoded to `%7C`, is that the case? What is the exact value of `URL` after you have performed the encoding? – dave.c Jun 17 '14 at 13:37
  • http://maps.google.com/maps/api/staticmap?path%3Dcolor%3A0x0000ff%7Cweight%3A5%7C40.737102%2C-73.990318%7C40.755823%2C-73.986397%26zoom%3D14%26size%3D400x400%26sensor%3Dfalse – Nithin Jun 17 '14 at 13:45

2 Answers2

1

Thanks for your help i got it in the following way...

URL = "http://maps.google.com/maps/api/staticmap?size=400x400&path=color:0x0000ff" +URLEncoder.encode("|weight:5|40.737102,-73.990318|40.755823,-73.986397", "UTF-8") +"&zoom=14&sensor=false";

Nithin
  • 503
  • 4
  • 19
0

It seems like the order of the parameters is important. I put the size=400x400 as the first part of the url and it works ok:

http://maps.google.com/maps/api/staticmap?size=400x400&path=color:0x0000ff|weight:5|40.737102,-73.990318|40.755823,-73.986397&zoom=14&sensor=false

this encodes to:

http://maps.google.com/maps/api/staticmap?size%3D400x400%26path%3Dcolor%3A0x0000ff%7Cweight%3A5%7C40.737102%2C-73.990318%7C40.755823%2C-73.986397%26zoom%3D14%26sensor%3Dfalse
dave.c
  • 10,910
  • 5
  • 39
  • 62