我之前使用 MaxMind GeoIP Lite 数据库取得了很好的成功。城市和国家数据库和API均可用。
用法示例如下:
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);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
16939 次 |
| 最近记录: |