【发布时间】:2011-01-16 11:06:15
【问题描述】:
java中可以根据IP地址知道城市名吗?
【问题讨论】:
-
你可能不得不使用谷歌的某种 api
标签: java ip-address zipcode ip-geolocation city
java中可以根据IP地址知道城市名吗?
【问题讨论】:
标签: java ip-address zipcode ip-geolocation city
你用的是jsp还是什么?对于客户端上的城市名称,您可以使用谷歌的 API,它将返回与 IP 映射的用户的地理详细信息。正如谷歌的文档所说,您可以获得以下内容
填充后,google.loader.ClientLocation 对象将填充以下 Metro 级别粒度属性:
* 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 代码指向它们,然后就可以使用了。简单明了。
【讨论】: