如何根据java中的IP地址获取城市名称? [英] How to get city name based on IP address in java?

查看:806
本文介绍了如何根据java中的IP地址获取城市名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Is it possible to know the city name based on IP address in java?

推荐答案

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

are you using jsp or what ? for city name over client side you can use google's API which will return you the geographical details of the user mapped with the IP. As google's documentation say you can get the following

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

When populated, the google.loader.ClientLocation object is populated with the following metro-level granularity properties:

* 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/上的完整文档。

这篇关于如何根据java中的IP地址获取城市名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆