使用Google API根据地址查找坐标

时间:2019-10-10 07:59:52

标签: python-3.x pandas geocode

我有一个以地址(4k地址)为列的df,想使用Google api获取坐标和密码。

Df = 
Address
   Bibwewadi,Pune,Pune,India
   Lohegaon,Pune,Pune,India
   Dhanori,Pune,Pune,India
   Wagholi,Pune,Pune,India

这是我的代码

import googlemaps
 gmaps_key = googlemaps.Client(key = " ")
 df['LAT'] = None
 df['LON'] = None

for i in range (0,len(df),1):
 geocode_result = gmaps_key.geocode(df.iat[i,0])
  try:
     lat = geocode_result[0]["geometry"]["location"]["lat"]
     lon = geocode_result[0]["geometry"]["location"]["lat"]
     df.iat[i,df.columns.get_loc("LAT")] = lat
     df.iat[i,df.columns.get_loc("LON")] = lon
  except:
     lat = None
     lon = None

当我检查时得到的坐标不正确

0 个答案:

没有答案