Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java library to get geo-code from ipaddress

Tags:

java

geocoding

My application knows the IP address of the user. We need to identify the city, state, country of the user and latitude & longitude of the user.

Is there a java library that can do this?

If there is none, what is algorithm or data-source used to convert IP address to geo-graphic location?

like image 906
Nambi Avatar asked Jan 16 '23 05:01

Nambi


2 Answers

http://www.maxmind.com/app/developers provides a local database and java classes to calculate the location information from IP address. I did some testing. The results seem to be good.

bbc.co.uk: 212.58.241.131 : 51.283295,-0.23330688;Tadworth,N7,United Kingdom,null
home: 76.126.242.196 : 37.369705,-122.0214;Sunnyvale,CA,United States,94086
google.com: 74.125.224.133 : 37.419205,-122.0574;Mountain View,CA,United States,94043
tcs.in: 202.71.129.225 : 28.666702,77.216705;Delhi,07,India,null
ebay.com: 66.135.205.13 : 37.280304,-121.956696;Campbell,CA,United States,95008
etrade.com: 12.153.224.22 : 34.091797,-84.2209;Alpharetta,GA,United States,30005
whitehouse.gov: 72.247.136.110 : 42.362595,-71.0843;Cambridge,MA,United States,02142

Here is the link to the junit testcase I used, GeoLiteCityTest.java

MaxMind provides java classes, but not jars. So, I have created a maven project that can build the code and generate jars. Here is the GitHub Project https://github.com/snambi/GeoIP

If you need to use this library in your maven project, add the following dependency

<dependency>
   <groupId>org.geomind</groupId>
   <artifactId>geoip</artifactId>
   <version>1.2.8</version>
</dependency>

Add the following repository configuration, under "repositories" in the pom.xml

<repository>
   <id>geoip</id>
   <url>http://snambi.github.com/maven/</url>
</repository>
like image 124
Nambi Avatar answered Jan 18 '23 23:01

Nambi


Yup: http://www.maxmind.com/app/developers

They provide a Java API (among others).

like image 26
mnuss Avatar answered Jan 19 '23 00:01

mnuss