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

末鹿安然 提交于 2020-01-21 05:25:07

问题


I am looking for the sample code to get Exact Location of IP. I did goggling but haven't find any Sample code. Thank You..


回答1:


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);
}


来源:https://stackoverflow.com/questions/16185703/sample-code-for-finding-location-using-ip-address-in-java

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