[Python & 高德地图] API调用学习历程(一)

[一]正逆地理编码调用

#地理编码调用
def geo(address: str,city = None)->dict:
    parameters = {'key':key,
                  'city':city,
                  'citylimit':True,
                  'address':address
                  }
    r = requests.get("https://restapi.amap.com/v3/geocode/geo?parameters",params = parameters)
    data = r.json()['geocodes'][0]['location']
    print(data)
    return data

#逆地理编码调用
def regeo(location: str,radius = str,batch = str)->dict:
    parameters = {'key':key,
                  'location':location,
                  'radius':radius,
                  'batch':batch
                  }
    r = requests.get("https://restapi.amap.com/v3/geocode/regeo?parameters",params = parameters)
    data = r.json()['regeocodes'][0]['formatted_address']
    #data = r.json()#当调用多个坐标时需要打印出来用for循环依次输出位置
    print(data)
    return data

大概思路如程序所示,使用者仅仅稍作修改即可达到所需功能。

你可能感兴趣的:(高德地图API相关)