I have the latitude and longitude of places in a dataframe. I am looking to get the zip code using Google Maps API. Now I am trying to write a loop to do this and it won't work. The problem is the gmaps variable latlng
How do I get two floats that are my variables into one variable that is latlng
?
I have successfully done this went I "hardcode" in the coordinates.
for index, row in bike_df.iterrows():
lat = row["Starting Station Latitude"]
long = row["Starting Station Longitude"]
target_url = ('https://maps.googleapis.com/maps/api/geocode/json?'
'latlng=34.052898,-118.241562&key={0}').format(gkey)
response = requests.get(target_url).json()
try:
print(response['results'][0]['address_components'][7]['long_name'])
except:
print(f"Could not {index} find zip")
for index, row in bike_df.iterrows():
lat = row["Starting Station Latitude"]
long = row["Starting Station Longitude"]
target_url = ('https://maps.googleapis.com/maps/api/geocode/json?'
'latlng=lat,long&key={0}').format(gkey)
response = requests.get(target_url).json()
try:
print(response['results'][0]['address_components'][7] .
['long_name'])
except:
print(f"Could not {index} find zip")
It just runs and runs without any output.