小白闯

导航

python调用百度API获取地点经纬度

import requests
import pandas as pd
import numpy as np
import copy

 

area = pd.read_excel('D:/AREA.xlsx')

#调用百度API,得到地点的经纬度信息
def geocodeB(address):
base = url = "http://api.map.baidu.com/geocoder?address=" + address + "&output=json&key=FLgj6DRO9iKvPjFk9Ms8OBfwjGQKgIT9"
response = requests.get(base)
answer = response.json()
return answer['result']['location']['lng'],answer['result']['location']['lat']
area_A = copy.copy(area)
for i in range(area.shape[0]):
area_A.iloc[i,0] = geocodeB(area.iloc[i,0])
#area_A.to_excel('D:/area_A.xlsx', index=False) #输出经纬度信息

 

posted on 2019-09-05 11:02  李小白cc  阅读(1630)  评论(0编辑  收藏  举报