-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgooglemapstester.py
45 lines (29 loc) · 1.04 KB
/
googlemapstester.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
import googlemaps
import pandas as pd
import os
import json
import helper
try:
#What is shapes_df also had the trips it is a part of?
stops_df = pd.read_csv("agencies/bart/stops.txt")
except Exception as e:
print os.getcwd()
print e
gmaps = googlemaps.Client(key='AIzaSyB_yzsaBUOOo3ukoeDvtjg5Q32IGSkBUvU')
stop1 = stops_df.iloc[0]
stop2 = stops_df.iloc[1]
print "stop 1: " + stop1['stop_id']
print "stop 2: " + stop2['stop_id']
routes = gmaps.directions(origin={'lat': stop1['stop_lat'], 'lng': stop1['stop_lon']},
destination={'lat': stop2['stop_lat'], 'lng': stop2['stop_lon']},
mode="walking", units='imperial')
legs = routes[0]['legs']
totalDistance = 0
totalDuration = 0
print legs[0]['distance']
for x in range(0, len(legs)):
totalDistance += helper.meters_to_miles(legs[x]['distance']['value'])
totalDuration += legs[x]['duration']['value']
print 15953 / 1609.344
print "totalDistance:" + str(totalDistance)
print "totalDuration:" + str(totalDuration)