用于从ipaddress获取地理代码的Java库 [英] Java library to get geo-code from ipaddress

查看:130
本文介绍了用于从ipaddress获取地理代码的Java库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序知道用户的IP地址。
我们需要确定用户的城市,州,国家和纬度&用户的经度。

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.

是否有可以执行此操作的java库?

Is there a java library that can do this?

如果没有,什么是用于将IP地址转换为地理位置的算法或数据源?

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

推荐答案

http://www.maxmind.com/app/developers 提供本地数据库和java类来计算IP地址的位置信息。我做了一些测试。结果似乎很好。

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

以下是我使用的junit测试用例的链接, GeoLiteCityTest.java

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

MaxMind提供java类,但不提供jar。所以,我创建了一个可以构建代码并生成jar的maven项目。这是GitHub项目 https://github.com/snambi/GeoIP

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

如果您需要在maven项目中使用此库,请添加以下依赖项

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>

在pom.xml中的存储库下添加以下存储库配置

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

<repository>
   <id>geoip</id>
   <url>http://snambi.github.com/maven/</url>
</repository>

这篇关于用于从ipaddress获取地理代码的Java库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆