Skip to content

Instantly share code, notes, and snippets.

@bamnet
Created July 22, 2019 03:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bamnet/0e131833a23d4265ee3ebb079942af55 to your computer and use it in GitHub Desktop.
Save bamnet/0e131833a23d4265ee3ebb079942af55 to your computer and use it in GitHub Desktop.
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