我正在寻找示例代码来获取IP的精确位置。 我做了goggling但没有找到任何示例代码。 谢谢..
答案 0 :(得分:2)
我之前使用MaxMind GeoIP Lite数据库取得了很好的成功。 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);
}