I’m trying to integrate some Google maps bits into my Java web app using the Google Maps static API. For the moment I’m just trying to get a map, any map. Their example:
http://maps.google.com/maps/api/staticmap?center=40.714728,-73.998672&zoom=12&size=400x400&sensor=false
works fine from my browser. However the Java HTTP client software I am using (the one from Apache’s http components, version 4.0.2) insists that I encode my URIs, so I end up with this:
http://maps.google.com/maps/api/staticmap?center%3D40.714728%2C-73.998672%26zoom%3D12%26size%3D400x400%26sensor%3Dfalse
which doesn’t work. I would happily not encode my URIs but the Apache client fails if I don’t. So my question is how can I either:
- persuade Apache’s client to use the plain URI or
- get the encoded URI into a form Google will accept
?
As Pekka suggested you need to leave to
&and=unencoded.Your encoded url
vs unencoded
&(%26) and=(%3D) (working)Apache’s HTTPComponents HTTP Client has a lot of interfaces with which you can build your request URL. To make sure that the proper parts of the URL are encoded I would suggest using this method: