-
Notifications
You must be signed in to change notification settings - Fork 0
/
gmaps.py
executable file
·45 lines (36 loc) · 937 Bytes
/
gmaps.py
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
#!/bin/bash /Users/FWerpers/.virtualenvs/jodlHack/bin/fwpy
# coding: utf-8
import googlemaps
import ConfigParser
import json
# API key stored in config file
config = ConfigParser.RawConfigParser()
config.read('config.cfg')
API_key = config.get('Credentials', 'API_key')
gmaps = googlemaps.Client(key=API_key)
def get_coords(address):
r = gmaps.geocode(address)
location = r[0]['geometry']['location']
lat = location['lat']
lng = location['lng']
return((lat, lng))
def get_address(coords):
r = gmaps.reverse_geocode(coords)
addr = r[0]['formatted_address']
return addr
def get_jodl_location(coords, acc):
r = gmaps.reverse_geocode(coords)
city = r[5]['address_components'][0]['short_name']
country = r[-1]['address_components'][0]['short_name']
lat = coords[0]
lng = coords[1]
loc = {
'loc_accuracy': acc,
'city': city,
'loc_coordinates': {
'lat': lat,
'lng': lng
},
'country': country
}
return loc