2013-04-24 52 views
3

我正在寻找示例代码来获取IP的精确位置。 我做了护目镜,但没有找到任何示例代码。 谢谢。在java中使用IP地址查找位置的示例代码?

+0

让我测试。 nullPainter – 2013-04-24 07:22:03

+0

请注意,MaxMind数据库的免费版本更新频率比商业版本要低。还要注意的是“确切位置”的概念是相对的,当涉及到IP,并且可以根据您的ISP的基础,这取决于你的国家,ISP等大小 – nullPainter 2013-04-24 07:29:46

回答

1

我以前使用过的MaxMind GeoIP的精简版数据库,以良好的成功。 city and country databasesAPIs都可用。

使用的一个例子是:

File dbfile = new File("db/GeoLiteCity.dat"); 
LookupService lookupService = new LookupService(dbfile, LookupService.GEOIP_MEMORY_CACHE); 

Location location = lookupService.getLocation(ipAddress); 

// Populate region. Note that regionName is a MaxMind class, not an instance variable 
if (location != null) { 
    location.region = regionName.regionNameByCode(location.countryCode, location.region); 
} 
+0

在这里HTTP试试这个代码城市:/ /www.mkyong.com/java/java-find-location-using-ip-address/ – 2015-12-15 10:16:34