Sample code for finding location using IP address in java? [duplicate]

坚强是说给别人听的谎言 提交于 2019-11-30 23:47:18

I've used the MaxMind GeoIP Lite database to good success before. Both city and country databases and APIs are available.

An example of usage is:

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);
}
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!