首先普通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'}};
只要在他页面里注册用户获得授权的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 ();
}
}
}