By using Java API Geocoder, it is easy to get geographical information of any location. The response will be in JSON or XML format.
Write the following example to get Latitude/Longitude from Zip code:
String postCode = "07001"; // you can use address of any location here instead of zipcode
final Geocoder geocoder = new Geocoder();
GeocoderRequest geocoderRequest = new GeocoderRequestBuilder().setAddress(postCode).getGeocoderRequest();
GeocodeResponse geocoderResponse = geocoder.geocode(geocoderRequest);
List results = geocoderResponse.getResults();
System.out.println("results : "+results); //This will print geographical information
float latitude = results.get(0).getGeometry().getLocation().getLat().floatValue();
float longitude = results.get(0).getGeometry().getLocation().getLng().floatValue();
System.out.println("Lat/Long : " + latitude +" , "+longitude);
Write the following Maven configuration in pom.xml file in your project:
<dependency>
<groupId>com.google.code.geocoder-java</groupId>
<artifactId>geocoder-java</artifactId>
<version>0.5</version>
Hope this will help you :)
1 Comment(s)