python使用高德地图api实现批量查询地址经纬度

新手尝试

import requests
import pandas as pd
import csv
data = pd.read_csv('地址.csv',engine='python')#导入地址的csv文件
data = data['地址']#选择地址列
lis = []
def gaode():
    for i in data:
        para = {
            'key':'你的key',
            'address':i,
            'city':'需要查询的城市'
        }
        url = 'https://restapi.amap.com/v3/geocode/geo?'
        req = requests.get(url,para)
        req = req.json()
        if req['infocode']=='10000':
            w = req['geocodes'][0]['formatted_address']
            z = req['geocodes'][0]['location']
            print(w)
            print(z)
            d = (w, z)
        else:
            print('查询不到')
        lis.append(d)

    t = ['位置','经纬度']
    with open('高度地图位置.csv', 'w', newline='')as f:
        writer = csv.writer(f)
        writer.writerow(t)
        writer.writerows(lis)
if __name__ == '__main__':
    gaode()

你可能感兴趣的:(python使用高德地图api实现批量查询地址经纬度)