Friday, 15 May 2015

The Google Geocoding API


Nowadays the word Google has become the synonym for "Search". To find any information we will just Google it. The term Googling has now become a phrase in English! It has now become one of my favourite word. Let's see how we can get the details about a place using Google.
Geocoding is the process of converting addresses to geographical co ordinates. The reverse process is termed as Reverse geocoding. The Google Geocoding API provides a direct way to access these services via an HTTP request.

Usage Limits

The Google Geocoding API has the following limits in place:
Users of the free API:
2,500 requests per 24 hour period.
5 requests per second.
Google Maps API for Work customers:
100,000 requests per 24 hour period.
10 requests per second.

Geocoding API Request Format

A Geocoding API request must be of the following form:
https://maps.googleapis.com/maps/api/geocode/output?parameters
where output can be either JSON or XML

Maven Dependency:

<dependencies>
  <dependency>
    <groupId>com.google.code.geocoder-java</groupId>
    <artifactId>geocoder-java</artifactId>
    <version>0.16</version>
  </dependency>
</dependencies>

Sample:

import java.io.IOException;

import com.google.code.geocoder.Geocoder;

import com.google.code.geocoder.GeocoderRequestBuilder;
import com.google.code.geocoder.model.GeocodeResponse;
import com.google.code.geocoder.model.GeocoderRequest;


public class Main {


public static void main(String args[]) throws IOException{


final Geocoder geocoder = new Geocoder();
GeocoderRequest geocoderRequest = new GeocoderRequestBuilder().setAddress("Trivandrum, India").setLanguage("en").getGeocoderRequest();
GeocodeResponse geocoderResponse = geocoder.geocode(geocoderRequest);
System.out.println(geocoderResponse);
}
}


Result:


GeocodeResponse{status=OK, results=[GeocoderResult{types=[locality, political], formattedAddress='Thiruvananthapuram, Kerala, India', addressComponents=[GeocoderAddressComponent{longName='Thiruvananthapuram', shortName='TVM', types=[locality, political]}, GeocoderAddressComponent{longName='Thiruvananthapuram', shortName='TVM', types=[administrative_area_level_2, political]}, GeocoderAddressComponent{longName='Kerala', shortName='KL', types=[administrative_area_level_1, political]}, GeocoderAddressComponent{longName='India', shortName='IN', types=[country, political]}], geometry=GeocoderGeometry{location=LatLng{lat=8.524139099999999, lng=76.9366376}, locationType=APPROXIMATE, viewport=LatLngBounds{southwest=LatLng{lat=8.3867048, lng=76.84168699999999}, northeast=LatLng{lat=8.6127611, lng=77.0070362}}, bounds=LatLngBounds{southwest=LatLng{lat=8.3867048, lng=76.84168699999999}, northeast=LatLng{lat=8.6127611, lng=77.0070362}}}, partialMatch=false}]}




Never Ever Give UP!!

No comments:

Post a Comment