-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
45 lines (31 loc) · 1.08 KB
/
Copy pathmain.py
File metadata and controls
45 lines (31 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#
# https://developers.google.com/maps/documentation/geocoding/intro
#
import googlemaps
API_KEY = '<YOUR-API-KEY>'
gmaps = googlemaps.Client(key=API_KEY)
# convert address to lat,long
results = gmaps.geocode('221B Baker Street, London, United Kingdom')
for key in results[0].keys():
print('key:', key)
print('-----')
item = results[0]
print('formatted_address:', item['formatted_address'])
print('lat:', item['geometry']['location']['lat'])
print('lng:', item['geometry']['location']['lng'])
print('location:', item['geometry']['location'])
for part in item['address_components']:
print(part)
print('---')
print('address_components:', item['address_components'])
print('formatted_address:', item['formatted_address'])
print('geometry:', item['geometry'])
print('place_id:', item['place_id'])
print('types:', item['types'])
print('-----------------------------------------')
# convert lat,long to (nearest?) addresses
result = gmaps.geocode('51.523767 -0.1585557')
for item in result:
for part in item['address_components']:
print(part['long_name'])
print('---')