Thursday, 30 May 2013

Get Location Based on IP Address

There are many vendor available in market that provides REST service to get Location based on IP Address. In our example we have used IPInfoDB.

Step 1) Create an account with IPInfoDB: http://ipinfodb.com/register.php



Once account is created, you will receive an Account Activation link from IPInfoDB:

Activate the account.

Step 2) Login into IPInfoDB and under Overview Tab, copy the API Key. Using this API Key we will    call IPInfoDB Rest API to get Location.

Step 3) Java Code:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;

public class IPInfoDB {
 public static void main(String[] args) {
  new IPInfoDB().getClientLatLng("IP_ADDRESS");
 }
 
 public void getClientLatLng(String ip){
  if(ip!=null && !ip.equals(""))
  {
   try {
    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpPost postRequest = new HttpPost(
      "http://api.ipinfodb.com/v3/ip-city/?key={YOUR_API_KEY}&ip=" + ip);
    HttpResponse response = httpClient.execute(postRequest);
 
    if (response.getStatusLine().getStatusCode() != 201) {
     /*
      * throw new RuntimeException("Failed : HTTP error code : " +
      * response.getStatusLine().getStatusCode());
      */
     System.out.println("StatusCode: "
       + response.getStatusLine().getStatusCode());
    }
 
    BufferedReader br = new BufferedReader(new InputStreamReader(
      (response.getEntity().getContent())));
 
    String output;
    System.out.println("Output from Server .... \n");
    while ((output = br.readLine()) != null) {
     System.out.println(output);
    }
 
    httpClient.getConnectionManager().shutdown();
   } catch (MalformedURLException e) {
    e.printStackTrace();
   } catch (IOException e) {
    e.printStackTrace();
   }
  }
 }
}



OUTPUT:

StatusCode: 200
Output from Server .... 

OK;;10.162.1.1;IN;INDIA;GUJARAT;AHMEDABAD;-;23.0333;72.6167;+05:30
IP Info DB


Thats it!
Categories: , , , , ,

5 comments:

  1. Nice valuable information….I got my IP address details from IP-Details.com

    ReplyDelete
  2. Great article...thanks a lot sunil..after a week struggle i found ur site..and it made things so easy

    ReplyDelete
  3. After selecting google map location, it will be displayed on store front.OCMOD extension.Gmap Geo Address

    ReplyDelete
  4. Tesão Fatal 2 As Panteras o maior taradão dos cinemas porno esta de volta o Dhones Portela e com as melhores atriz como Ju Panteras para abrilhantar a mais esse filme espetacular da Panteras. Muito mais quente que a primeira edição o segundo vem cheio de mulheres gatas e disposta a fazer de tudo que se relaciona ao sexo. Elas adoram uma gaganta profunda e pira a cabeça de seus taradinhos mais safadinhos que tem no mundo do sexo. E com time desse de gatas os caras estara bem preparados para dar aquela foda nesses safadinhos que adoram fazer aquela sacanagem .
    Tesão Fatal 2 As Panteras || Download do vídeo

    ReplyDelete
  5. Ah, HOT LEGS! Now this is what the Golden Age of Adult Films is all about! Alessandro cassioli bob Chinn, by this point a veteran of adult alessandro cassioli cinema whose name just screams quality, directs a first-rate cast performing a first-rate script, alessandro cassioli shot by a first-rate crew of professionals. Alessandro cassioli not only does the film look alessandro cassioli terrific, full of clever camera work and sizzling sex scenes alessandro cassioli, it's just plain FUN!

    ReplyDelete

Find me on Facebook! Follow me on Twitter!