在java中使用IP地址查找位置的示例代码? [英] Sample code for finding location using IP address in java?

查看:199
本文介绍了在java中使用IP地址查找位置的示例代码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找示例代码来获取IP的精确位置。
我做了goggling但没有找到任何示例代码。
谢谢..

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..

推荐答案

我之前使用MaxMind GeoIP Lite数据库取得了很好的成功。 城市和国家/地区数据库 API

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

使用的一个例子是:

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

这篇关于在java中使用IP地址查找位置的示例代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆