如何根据java中的IP地址获取城市名称?

是否可以根据java中的IP地址知道城市名称?

你使用的是jsp还是什么? 对于客户端的城市名称,您可以使用谷歌的API,它将返回与IP映射的用户的地理详细信息。 正如谷歌的文档所说,你可以得到以下内容

填充后,将使用以下城域级粒度属性填充google.loader.ClientLocation对象:

* ClientLocation.latitude — supplies the low resolution latitude associated with the client's IP address * ClientLocation.longitude — supplies the low resolution longitude associated with the client's IP address * ClientLocation.address.city — supplies the name of the city associated with the client's IP address * ClientLocation.address.country — supplies the name of the country associated with the client's IP address * ClientLocation.address.country_code — supplies the name of the ISO 3166-1 country code associated with the client's IP address * ClientLocation.address.region — supplies the country specific region name associated with the client's IP address 

有关进一步参考,请参阅http://code.google.com/apis/ajax/documentation/上的完整文档。

您必须使用hostip.info等服务将IP映射到其物理位置,并为开发人员提供API以简化任务。

您可以在Google上找到许多其他服务,付费和免费。

如果其他人建议的在线API不适合您的应用程序,我之前已经成功使用了MaxMind GeoLite City ,它带有Java API(以及许多其他API)。 只需下载数据库文件,将API代码指向它们,然后就可以了。 简单明了。

Interesting Posts