1. 程式人生 > >js 定位當前城市之介面定位(搜狐、新浪、百度、騰訊API)

js 定位當前城市之介面定位(搜狐、新浪、百度、騰訊API)

1.搜狐API

<script src="http://pv.sohu.com/cityjson?ie=utf-8"></script>  
<script type="text/javascript">  
console.log(returnCitySN)  
//返回物件Object {cip: "122.70.200.146", cid: "110000", cname: "北京市"}
</script>

2.新浪API

<script src="http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js"
></script> <script> var msg = remote_ip_info; console.log(msg) //返回物件Object {ret: 1, start: -1, end: -1, country: "中國", province: "北京",city: "北京"…} </script>

3.新浪apijsonp

<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
<script type=
"text/javascript"> $.getScript('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js', function(_result) { if (remote_ip_info.ret == '1') { console.log('國家:' + remote_ip_info.country +'\n省:' + remote_ip_info.province + '\n市:' + remote_ip_info.city + '\n區:' + remote_ip_info.district +
'\nISP:' + remote_ip_info.isp + '\n型別:' + remote_ip_info.type + '\n其他:' + remote_ip_info.desc); //返回結果 國家:中國 省:北京 市:北京 區: ISP: 型別: 其他: } else { alert('沒有找到匹配的IP地址資訊!'); } });

4.百度地圖api

function showLocation(data) {
    console.log(data.content.address_detail.city);
}
$.getScript("http://api.map.baidu.com/location/ip?ak=百度地圖密匙&callback=showLocation");

百度文件

5.騰訊地圖api

$.getScript('https://apis.map.qq.com/ws/location/v1/ip?callback=showLocation&key=騰訊地圖密匙&output=jsonp')function showLocation(data) {
   console.log(data.result.ad_info.city)
}

騰訊文件