Skip to content

Instantly share code, notes, and snippets.

@enzzc
Created October 5, 2018 14:24
Show Gist options
  • Save enzzc/3fca73d2044ab655418ade5dd1ccaae9 to your computer and use it in GitHub Desktop.
Save enzzc/3fca73d2044ab655418ade5dd1ccaae9 to your computer and use it in GitHub Desktop.
import requests
MAPS_API_KEY = 'secret'
def geocode(address):
url = 'https://maps.googleapis.com/maps/api/geocode/json'
params = {
'address': address,
'key': MAPS_API_KEY
}
r = requests.get(url, params=params)
data = r.json()['results']
if data:
lat = data[0]['geometry']['location']['lat']
lng = data[0]['geometry']['location']['lng']
return lat, lng
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment