Skip to content

Commit

Permalink
✨ Adding Distance and Duration for each waypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
miticous committed Sep 25, 2020
1 parent ecec2af commit 8d2592f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/MapViewDirections.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ class MapViewDirections extends Component {
);
})).then(results => {
// Combine all Directions API Request results into one
const result = results.reduce((acc, { distance, duration, coordinates, fare, waypointOrder }) => {
const result = results.reduce((acc, { distance, duration, coordinates, fare, waypointOrder, steps }) => {
acc.coordinates = [
...acc.coordinates,
...coordinates,
Expand All @@ -199,6 +199,13 @@ class MapViewDirections extends Component {
...acc.waypointOrder,
waypointOrder,
];
acc.splitedSteps = steps.reduce((accumulator, step) => [
...accumulator,
{
distance: step.distance.value,
duration: step.duration.value,
},
], []);

return acc;
}, {
Expand All @@ -207,6 +214,7 @@ class MapViewDirections extends Component {
duration: 0,
fares: [],
waypointOrder: [],
splitedSteps: [],
});

// Plot it out and call the onReady callback
Expand Down Expand Up @@ -269,6 +277,7 @@ class MapViewDirections extends Component {
];
}, [])
),
steps: route.legs,
fare: route.fare,
waypointOrder: route.waypoint_order,
});
Expand Down

0 comments on commit 8d2592f

Please sign in to comment.