網上解決方案
1.通過搜狐接口

獲取方式如下:
//網頁端引入腳本
<script type="text/javascript" src="http://pv.sohu.com/cityjson?ie=utf-8"></script>
//JS端直接獲取
returnCitySN["cip"]
缺點:目前對於公網IP的地址只精確到省,沒有詳細的IP信息
2.通過淘寶接口

獲取方式不詳細介紹,不推薦此解決方案獲取
缺點:時不時就掛掉了獲取不到,非常不穩定
獲取方式通過跨域ajax獲取:
//JS AJAX
function() {
var data = { key: "這里填寫注冊騰訊api時返回的key" };//ip缺省時會自動獲取請求端的公網IP,
var url = "https://apis.map.qq.com/ws/location/v1/ip";
data.output = "jsonp";
$.ajax({
type: "get",
dataType: 'jsonp',
data: data,
jsonp: "callback",
url: url,
success: function (json) {
array = new Array;
array.push(json.result.ip);//公網IP
array.push(json.result.ad_info.province + json.result.ad_info.city + json.result.ad_info.district);//省市區
array.push(json.result.location.lat);//經度
array.push(json.result.location.lng);//緯度
return array;
},
error: function (err) {
//業務處理
}
});
}
缺點:需要注冊騰訊自己的key,目的在於控制調用騰訊位置接口服務的權限,注冊后還會有調用次數限制,個人和企業不同

推薦第三種獲取公網IP解決方案


