• 通过ip查询对方位置


    我们这里使用的是baidumap的高精度IP定位API的接口,具体说明可以参考baidu提供的文档

    使用前需要申请一个AK密钥类似于Kgcx......................xxl8w的样式

    http://api.map.baidu.com/highacciploc/v1?qcip=220.xxx.xx.113&qterm=pc&ak=Kgcx......................xxl8w&coord=bd09ll&extensions=1

    这是我的访问的URL,其中参数可以参考文档给出的定义

    下图是访问到的网页

    这里我主要写一个脚本,对抓到的html进行格式化

     1 # -*- coding: utf-8 -*-
     2 """
     3 Created on Wed Oct 12 12:40:24 2016
     4 
     5 @author: Administrator
     6 """
     7 import requests
     8 import json
     9 
    10 URL = 'http://api.map.baidu.com/highacciploc/v1?qcip=110.xxxx.31.6&qterm=pc&ak=Kgcx0pNF6.....................xl8w&coord=bd09ll&extensions=1'
    11 
    12 def get_html(url):
    13     headers = {'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/30.0.1581.2 Safari/537.36'}
    14     text = requests.get(url,headers=headers).text
    15     return text
    16 
    17 def formated_html(text):
    18     jo = json.loads(text) #或者直接用eval函数将text转成dict
    19     business = jo['content']['business']
    20     for k,v in jo['content']['address_component'].items():
    21         print k,':', v
    22     print 'formatted_address',':',jo['content']['formatted_address']
    23     print 'business',':',jo['content']['business']
    24     print 'location',':',jo['content']['location']
    25     
    26 if __name__ == '__main__':
    27     text = get_html(URL)
    28     formated_html(text)
    29     
    30     

    下面是格式化后的结果:

    但是官方给出了注意事项:成功率:综合定位成功率 65%  ,精度:90% 误差 80m 以内;95% 误差 350m

  • 相关阅读:
    动手实验01-----vCenter 微软AD认证配置与用户授权
    esxi 主机用户功能说明
    vCenter组件和服务
    配置vSphere Web Client超时值
    如何修改 Vmware vRealize Operations Manager Appliance root密码
    linux如何搭建sftp服务器
    Vmware vSphere 开启嵌套虚拟化
    在VS2013上配置OpenCV1.0
    FFmpeg深入分析之零-基础
    坚持看英文文档
  • 原文地址:https://www.cnblogs.com/fuzzier/p/6003626.html
Copyright © 2020-2023  润新知