2016年11月27日08:13:13
API服务地址:
http://lbsyun.baidu.com/index.php?title=webapi/high-acc-ip
使用方法:
第一步,申请密钥(AK) ,作为访问服务的依据;
第二步,拼写发送HTTP/HTTPS请求的URL,注意需使用第一步申请的AK;
第三步,接收HTTP/HTTPS请求返回的数据(JSON/JSONP格式)
服务地址:
http://api.map.baidu.com/highacciploc/v1
https://api.map.baidu.com/highacciploc/v1
注意:申请开发者认证的时候,使用163邮箱认证失败,不知道是为什么(2016年11月27日08:23:32)
测试地址:
http://api.map.baidu.com/highacciploc/v1?qcip=139.214.254.47&qterm=pc&ak=naW5VG6u5TELUZ2stDslQPsYirKoIOFz&coord=bd09ll&extensions=3
反馈结果:
{"content":{"location":{"lat":43.862307,"lng":125.332422},"locid":"fb823867162b178b3e180993e4638d41","radius":2060684,"confidence":0.2,"address_component":{"country":"中国","province":"吉林省","city":"长春市","district":"南关区","street":"人民大街","street_number":"5766号","admin_area_code":220102},"formatted_address":"吉林省长春市南关区人民大街5766号","business":"人民大街,南岭,南湖公园"},"result":{"error":161,"loc_time":"2016-11-27 08:36:41"}}
- import requests
- import json
-
- s = requests.session()
- url = ‘http://api.map.baidu.com/highacciploc/v1?qcip=139.214.254.47&qterm=pc&ak=YourKey&coord=bd09ll&extensions=3‘
- header = {‘User-Agent‘:‘Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:50.0) Gecko/20100101 Firefox/50.0‘}
- response = s.get(url, headers = header, timeout = 20)
- print(response.text)
-
- json = json.loads(response.text)
-
- print(‘位置:‘+str(json[‘content‘][‘formatted_address‘]))
- print(‘商圈:‘+str(json[‘content‘][‘business‘]))
- print(‘经度:‘+str(json[‘content‘][‘location‘][‘lat‘]))
- print(‘维度:‘+str(json[‘content‘][‘location‘][‘lng‘]))
- print(‘准确度:‘+str(json[‘content‘][‘confidence‘]))
-
=====================
输入结果
{"content":{"location":{"lat":43.862307,"lng":125.332422},"locid":"180d8c65fa25fefaf6eb9ae6481e1f4c","radius":2060684,"confidence":0.2,"address_component":{"country":"中国","province":"吉林省","city":"长春市","district":"南关区","street":"人民大街","street_number":"5766号","admin_area_code":220102},"formatted_address":"吉林省长春市南关区人民大街5766号","business":"人民大街,南岭,南湖公园"},"result":{"error":161,"loc_time":"2016-11-27 10:45:03"}}
位置:吉林省长春市南关区人民大街5766号
商圈:人民大街,南岭,南湖公园
经度:43.862307
维度:125.332422
准确度:0.2