获得当前IP的位置及经纬度的web服务

首先普通IP是无法获得详细经纬度的,只有通过网络服务才能获得

国内比较好用的是www.ip-look-up.com提供的Javascript api,只要在网页中写入如下语句

<script type="text/javascript" src="http://www.ip-look-up.com/Services/ipInfo.js"></script>
//他会在内存中返回一个Json数据只要点儿调用就好了
ipLocation = {'latitude':39.9289,'longitude':116.388,'address':{'city':'Beijing','region':'Beijing','country':'China','cnRegionName':'','cnCity':'','cnCountryName':'','country_code':'CN'}};


还有一个是 http://www.fraudlabs.com/   提供的webservice,返回xml

只要在他页面里注册用户获得授权的key,再下载人家提供的对应编程语言的功能类就能解析传入IP的地理位置了

修改Client.java里的对应内容测试      Java里别忘了引用必要的几个jar包(mail.jar,soap.jar,xercesImpl.jar,xml-apis.jar,xmlParserAPIs.jar)

public class Client 
{ 

	//Entry Point to this Application
	public static void main(String[] args) 
	{ 
		try 
		{
		//Create a proxy
		ApacheSoapProxy proxy = new ApacheSoapProxy ();

		//Invoke FraudLabsCheck() over SOAP and get the new OID
		//Require Parameter FraudLabsCheck(String IP, String LICENSE)
		String result = proxy.FraudLabs("148.229.0.123", "xx-xxxx-xxxx");
		
		//Print out the value
		System.out.println (result);
		}
		catch (java.net.MalformedURLException exception) 
		{
			exception.printStackTrace ();
		}
		catch (org.apache.soap.SOAPException exception) 
		{
			exception.printStackTrace ();
		}
	}
}


  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值