JS呼叫免費介面根據ip查詢位置
阿新 • • 發佈:2019-01-01
免費介面如下:
以新浪為例,呼叫jQuery的getScript()$.getScript('http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js', function() {
$("#depcity").val(getCity(remote_ip_info.city));
});
新浪的ip地址查詢介面返回值為:
var remote_ip_info = {"ret":1,"start":-1,"end":-1,"country":"\u4e2d\u56fd","province":"\u6c5f\u82cf","city":"\u5f90\u5dde","district":"","isp":"","type":"","desc":""};
百度免費介面:
http://api.map.baidu.com/location/ip?ak=F454f8a5efe5e577997931cc01de3974&ip=180.124.234.248
ak:金鑰
ip:ip地址
響應結果:
{ "address":"CN|江蘇|徐州|None|CHINANET|0|0", "content":{ "address_detail":{ "province":"江蘇省", "city":"徐州市", "district":"", "street":"", "street_number":"", "city_code":316 }, "address":"江蘇省徐州市", "point":{ "y":"4041039.6", "x":"13045462.3" } }, "status":0 }