Last active
May 29, 2024 13:19
-
-
Save pnavarrc/5379521 to your computer and use it in GitHub Desktop.
Using Python requests and the Google Maps Geocoding API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Using Python requests and the Google Maps Geocoding API. | |
# | |
# References: | |
# | |
# * http://docs.python-requests.org/en/latest/ | |
# * https://developers.google.com/maps/ | |
import requests | |
GOOGLE_MAPS_API_URL = 'http://maps.googleapis.com/maps/api/geocode/json' | |
params = { | |
'address': '221B Baker Street, London, United Kingdom', | |
'sensor': 'false', | |
'region': 'uk' | |
} | |
# Do the request and get the response data | |
req = requests.get(GOOGLE_MAPS_API_URL, params=params) | |
res = req.json() | |
# Use the first result | |
result = res['results'][0] | |
geodata = dict() | |
geodata['lat'] = result['geometry']['location']['lat'] | |
geodata['lng'] = result['geometry']['location']['lng'] | |
geodata['address'] = result['formatted_address'] | |
print('{address}. (lat, lng) = ({lat}, {lng})'.format(**geodata)) | |
# 221B Baker Street, London, Greater London NW1 6XE, UK. (lat, lng) = (51.5237038, -0.1585531) | |
bishvesh
commented
May 29, 2024
via email
NoOn May 29, 2024, at 5:26 AM, PabloGarcia00 ***@***.***> wrote:Re: ***@***.*** commented on this gist.Is it possible to do a text search and extract adresses, for instance "chinese restaurants, new york".—Reply to this email directly, view it on GitHub or unsubscribe.You are receiving this email because you commented on the thread.Triage notifications on the go with GitHub Mobile for iOS or Android.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment