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

来源:互联网 发布:c语言的且或非 编辑:程序博客网 时间:2024/04/30 04:54

首先普通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 Applicationpublic static void main(String[] args) { try {//Create a proxyApacheSoapProxy 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 valueSystem.out.println (result);}catch (java.net.MalformedURLException exception) {exception.printStackTrace ();}catch (org.apache.soap.SOAPException exception) {exception.printStackTrace ();}}}


原创粉丝点击