zoukankan      html  css  js  c++  java
  • 调用百度接口得到相关位置的标准地理位置信息

    (1)首先通过所给出的位置得到经纬度;

    (2)通过经纬度得到详细位置信息。

    #coding=UTF-8
    import json
    import sys
    
    import requests
    
    
    def getPosition(url):
        res = requests.get(url)
        json_data = json.loads(res.text)
        if json_data['status'] == 0:
            lat = json_data['result']['location']['lat']  # 纬度
            lng = json_data['result']['location']['lng']  # 经度
        else:
            print("Error output!")
            print(json_data)
            return json_data['status']
        return lat, lng
    
    
    def getplace_update(ak, dw):
        add_url = 'http://api.map.baidu.com/geocoding/v3/?address={Address}&output=json&ak={Ak}'.format(Address=dw, Ak=ak)
        lat, lng = getPosition(add_url)
        url = 'http://api.map.baidu.com/reverse_geocoding/v3/?ak=' + ak + '&output=json&coordtype=wgs84ll&location='+str(lat)+','+str(lng)
        result = requests.get(url)
        text = json.loads(result.text)
        address = text.get('result').get('addressComponent')
        city = address.get('city')
        province = address.get('province')
        district = address.get('district')
        if city == province:
            place = province+district
        else:
            place = province + city + district
        print(place)
    
    
    if __name__ == '__main__':
        reload(sys)
        sys.setdefaultencoding('utf8')
        ak = '###'
        dw = '冀州中学'
        getplace_update(ak, dw)

    运行截图:

  • 相关阅读:
    t
    溢出
    https://stackoverflow.com/questions/45591594/fetch-does-not-send-headers
    显示在用户屏幕上的缩略图
    cache buffer
    LZW
    t
    指针悬挂
    使用Linux服务器来通过网络安装和激活Windows 7 —— 一些基本原理
    在C++中如何动态分配一个二维数组
  • 原文地址:https://www.cnblogs.com/123456www/p/12495122.html
Copyright © 2011-2022 走看看