【问题标题】:How to get city name based on IP address in java?如何在java中根据IP地址获取城市名称?
【发布时间】:2011-01-16 11:06:15
【问题描述】:

java中可以根据IP地址知道城市名吗?

【问题讨论】:

  • 你可能不得不使用谷歌的某种 api

标签: java ip-address zipcode ip-geolocation city


【解决方案1】:

你用的是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/ 上的完整文档

【讨论】:

  • 是的,我正在使用 JSP infact JSF,感谢您的快速回复,如果您可以提供代码片段,那将非常有帮助!
【解决方案2】:

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

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

【讨论】:

    【解决方案3】:

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

    【讨论】:

    • 这项服务是否收费,如果是,请建议任何免费服务。 just-flick.com
    猜你喜欢
    • 2011-08-14
    • 1970-01-01
    • 2023-03-20
    • 1970-01-01
    • 2012-04-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多