繁体   English   中英

如何在Java中基于IP地址获取城市名称?

[英]How to get city name based on IP address in java?

是否可以基于Java中的IP地址知道城市名称?

您在使用jsp还是什么? 对于通过客户端提供的城市名称,您可以使用Google的API,该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不适合您的应用程序,那么我以前已经成功使用了Java API附带的MaxMind GeoLite City (还有许多其他API)。 只需下载数据库文件,将您的API代码指向它们,然后就可以使用了。 简单明了。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM