Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Adding Distance and Duration for each waypoint #156

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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