1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| class google_maps:
"""Class to call Google Maps API"""
def __init__(self, api_key):
self.api_key = api_key
def get_position(self, question):
"""Return the geographical coordinates of the parsed user input"""
google_maps = googlemaps.Client(key=self.api_key)
google_maps_result = google_maps.geocode(question, region='fr')
try:
address = google_maps_result[0]["formatted_address"]
lat = google_maps_result[0]["geometry"]["location"]["lat"]
lng = google_maps_result[0]["geometry"]["location"]["lng"]
return {
"address": address,
"latitude": lat,
"longitude": lng
}
except IndexError:
return "no result" |