Skip to content

Commit

Permalink
Error handling in route generation
Browse files Browse the repository at this point in the history
  • Loading branch information
vjdad4m committed Dec 9, 2023
1 parent 03b06b6 commit 7085a54
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions common/bkk_api/bkk_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,9 @@ def geocode_location(location):
def find_shortest_route_time(lat1, lon1, lat2, lon2):
# Request data from Google Maps API
gmaps = googlemaps.Client(key=os.environ['NEXT_PUBLIC_MAP_API_KEY'])
directions_result = gmaps.directions((lat1, lon1), (lat2, lon2))
return directions_result[0]['legs'][0]['duration']['value']
directions_result = gmaps.directions((lat1, lon1), (lat2, lon2), mode="walking")
try:
distance = directions_result[0]['legs'][0]['duration']['value']
except:
distance = 0
return distance

0 comments on commit 7085a54

Please sign in to comment.