python调用高德api实现地理逆编码

python 调用高德地图api实现地理逆编码返回所属城市

import requests
key_xjh = '你的key'
def regeo(location:str)->dict:
    """获取逆地理编码"""
    url ='https://restapi.amap.com/v3/geocode/regeo?parameters'
    param ={
        'key':key_xjh,
        'location':location,
        'output':'json'
    }
    response = requests.get(url,params=param)
    data = response.json()
    return data['regeocode']['addressComponent']['city']

坐标整理

xtmp = 104.07649
ytmp = 30.48686
locations=str(xtmp)+','+str(ytmp)

例子

city2 = regeo(locations)

你可能感兴趣的:(json,python)