JS调用免费接口根据ip查询位置

免费接口如下:

新浪的IP地址查询接口:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js

新浪多地域测试方法:http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=js&ip=218.192.3.42

搜狐IP地址查询接口(默认GBK):http://pv.sohu.com/cityjson

搜狐IP地址查询接口(可设置编码):http://pv.sohu.com/cityjson?ie=utf-8

搜狐另外的IP地址查询接口:http://txt.go.sohu.com/ip/soip

以新浪为例,调用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
}


posted on 2016-08-28 21:53  菜鸟Z  阅读(542)  评论(0编辑  收藏  举报

导航