簡體   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