3
我正在尋找示例代碼來獲取IP的精確位置。 我做了護目鏡,但沒有找到任何示例代碼。 謝謝。在java中使用IP地址查找位置的示例代碼?
我正在尋找示例代碼來獲取IP的精確位置。 我做了護目鏡,但沒有找到任何示例代碼。 謝謝。在java中使用IP地址查找位置的示例代碼?
我以前使用過的MaxMind GeoIP的精簡版數據庫,以良好的成功。 city and country databases和APIs都可用。
使用的一個例子是:
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);
}
在這裏HTTP試試這個代碼城市:/ /www.mkyong.com/java/java-find-location-using-ip-address/ – 2015-12-15 10:16:34
讓我測試。 nullPainter – 2013-04-24 07:22:03
請注意,MaxMind數據庫的免費版本更新頻率比商業版本要低。還要注意的是「確切位置」的概念是相對的,當涉及到IP,並且可以根據您的ISP的基礎,這取決於你的國家,ISP等大小 – nullPainter 2013-04-24 07:29:46