*
* @param addressText the address to look
* @return the latitude and longitude information
*/
public static LatLng getAddressCoordinates(String addressText) {
LatLng coordinates = null;
GetMethod locateAddressGET = null;
HttpClient client = null;
try {
String addressUrlEncoded = URLEncoder.encode(addressText, "UTF-8");
String locationFindURL = "http://maps.google.com/maps/api/geocode/json?sensor=false&address="+addressUrlEncoded;
client = new HttpClient();
locateAddressGET = new GetMethod(locationFindURL);
int httpRetCode = client.executeMethod(locateAddressGET);
if(httpRetCode == HttpStatus.SC_OK){
String responseBodyAsString = locateAddressGET.getResponseBodyAsString();
ObjectMapper mapper = new ObjectMapper();
mapper.configure(JsonParser.Feature.ALLOW_UNQUOTED_FIELD_NAMES, true);
mapper.configure(JsonParser.Feature.ALLOW_SINGLE_QUOTES, true);
mapper.configure(JsonParser.Feature.ALLOW_COMMENTS, true);
JsonNode jsonRoot = mapper.readTree(responseBodyAsString);
JsonNode location = jsonRoot.path("results").get(0).path("geometry").path("location");
JsonNode lat = location.get("lat");
JsonNode lng = location.get("lng");
coordinates = new LatLng(lat.asDouble(),lng.asDouble());
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if(locateAddressGET!=null) locateAddressGET.releaseConnection();