I would like to obtain the coordinates from a series of addresses.
After running the code it shows me the following error after in time, it does not return the coordinates sometimes just for the first address. I do not know if it's a problem with the code or the permissions and strictures of the Google APIKey.
Error:
File "C:\Users\...\AppData\Local\Continuum\anaconda3\lib\site-packages\googlemaps\client.py", line 210, in _request
raise googlemaps.exceptions.Timeout()
Timeout
Code:
import pandas as pd
xl = pd.ExcelFile('Prueba.xlsx')
df = xl.parse('Sheet1')
df
#%%
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"]["lng"]
df.iat[i, df.columns.get_loc("LAT")] = lat
df.iat[i, df.columns.get_loc("LON")] = lon
except:
lat = None
lon = None
df