• 利用百度地图API实现地址和经纬度互换查询


     1 import json
     2 import requests
     3 
     4 
     5 def baiduMap(input_para):
     6     headers = {
     7         'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit'
     8                       '/537.36 (KHTML, like Gecko) Chrome/53.0.2785.143 Safar'
     9                       'i/537.36'
    10     }
    11     if not isinstance(input_para, str):
    12         input_para = str(input_para)
    13     base_url = 'http://api.map.baidu.com/geocoder/v2/'
    14     ak = 'your ak'
    15     output = 'json'
    16     url = base_url + '?' + input_para + '&output=' + output + '&ak=' + ak
    17     req = requests.get(url, headers=headers).text
    18     temp = json.loads(req)
    19     return temp
    20 
    21 def getLngLat(address):
    22     place = 'address=' + address
    23     temp = baiduMap(place)
    24     if 'result' in temp.keys():
    25         lat = temp['result']['location']['lat']
    26         lng = temp['result']['location']['lng']
    27         return lat, lng
    28     else:
    29         print(address + '无法访问')
    30 
    31 # lat_lng: tuple格式
    32 def getPlace(lat_lng):
    33     if not isinstance(lat_lng, str):
    34         lat_lng = str(lat_lng)
    35     lat_lng = 'location=' + lat_lng[1:-1]
    36     temp = baiduMap(lat_lng)
    37     if 'result' in temp.keys():
    38         return temp['result']['formatted_address']
    39     else:
    40         print('经纬度' + lat_lng + '无法访问')
  • 相关阅读:
    音律入门
    [转]MIDI常识20条
    Java使用代理服务器
    java8日期时间
    误删课表系统
    Uncaught Error: Bootstrap tooltips require Tether (http://github.hubspot.com/tether/)
    SpringBoot应用部署[转]
    如何学习新技术
    Maven使用archetype迅速生成项目骨架
    两个月打工总结
  • 原文地址:https://www.cnblogs.com/laresh/p/8177636.html
Copyright © 2020-2023  润新知