-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgeocode.py
More file actions
24 lines (19 loc) · 713 Bytes
/
geocode.py
File metadata and controls
24 lines (19 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
import httplib2
import json
#
# Return geo code location of a location, using the google maps api.
#
def get_geo_code_location(input_string):
google_api_key = "<API key>"
location_string = input_string.replace(" ", "+")
url = ('https://maps.googleapis.com/maps/api/'
'geocode/json?address=%s&key=%s' % (
location_string, google_api_key))
h = httplib2.Http()
response, content = h.request(url, 'GET')
result = json.loads(content)
return result
# latitude = result['results'][0]['geometry']['location']['lat']
# longitude = result['results'][0]['geometry']['location']['lng']
# return (latitude, longitude)
print get_geo_code_location(raw_input())