Created
July 22, 2019 03:42
-
-
Save bamnet/0e131833a23d4265ee3ebb079942af55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
async function routeBetween( | |
directionSvc: import("./modern_services").DirectionService, | |
parks: Park[] | |
) { | |
const waypoints: google.maps.DirectionsWaypoint[] = parks.map((p) => ({ location: p.place })); | |
const req: google.maps.DirectionsRequest = { | |
origin: 'New York Penn Station', | |
destination: 'New York Penn Station', | |
optimizeWaypoints: true, | |
travelMode: google.maps.TravelMode.WALKING, | |
waypoints: waypoints, | |
}; | |
return directionSvc.routeAsync(req).then((res) => { | |
const seconds = res.routes[0].legs.reduce((a, b) => (a + b.duration.value), 0); | |
return <TripSummary>{ | |
parks: res.routes[0].waypoint_order.map(i => parks[i]), | |
duration: seconds, | |
path: res.routes[0].overview_path, | |
}; | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment