-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmap_distance.py
25 lines (18 loc) · 1004 Bytes
/
map_distance.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
def distance_calculator(db, datetime, id, date, session):
gmaps = googlemaps.Client(key='AIzaSyDVe_UbuxI4Hw2LO-mfJWQfSKfNFmVYExE')
# Get the start and end points' latitude and longitude
start_point = (6.7971762, 79.9020273)
end_point = (6.7977657, 79.9021842)
# Get directions between the start and end points
directions_result = gmaps.directions(start_point, end_point)
# Extract distance, start address, and end address from the directions result
distance = directions_result[0]['legs'][0]['distance']['text']
start_address = directions_result[0]['legs'][0]['start_address']
end_address = directions_result[0]['legs'][0]['end_address']
# Update the database with the distance and addresses
db.child("history").child(id).child(date).child(session).update(
{"dst": distance})
db.child("history").child(id).child(date).child(session).update(
{"strAd": start_address})
db.child("history").child(id).child(date).child(session).update(
{"endAd": end_address})