0
votes

I have two columns df['latitude'] and df['longitude'] and I am trying to reverse geocode them into full address google maps in df['Address']. However, I am not very successful. Is there a better way of doing this? I am using Geocoder package.

This is a sample from dataframe

\\ lat, lon 48.7082,2.2797 48.7577,2.2188 47.8333,2.2500 48.9833,1.7333 47.9333,1.9181 46.2735,4.2586 \\

2

2 Answers

0
votes

You can use the google maps API . You will need to use python 3.5 or higher and need to get a service key. You can get a API key using cloud console . There are wrappers out there that should make your job easier.

Google Maps API for client services

Wrapper

0
votes

First set your api key for google maps access:

export GOOGLE_API_KEY=<Secret API Key>
export GOOGLE_CLIENT=<Secret Client>
export GOOGLE_CLIENT_SECRET=<Secret Client Secret>

Then execute the following code to use "reverse" geocoding to create a location from a set of lat lon coordinates:

import geocoder
import pandas as pd

df = pd.DataFrame([{'lat':48.7082, 'lon':2.2797}, {'lat':48.7577,'lon':2.2188})

for index, row in df.iterrows():
    g = geocoder.google([row['lat'], row['lon']], method='reverse')
    print(g.json)