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

I have added source and destination Address in porps onReady call back function #175

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
15 changes: 12 additions & 3 deletions src/MapViewDirections.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,14 +183,15 @@ class MapViewDirections extends Component {
})
);
})).then(results => {
// Combine all Directions API Request results into one
const result = results.reduce((acc, { distance, duration, coordinates, fare, legs, waypointOrder }) => {
const result = results.reduce((acc, { distance, duration, coordinates, fare, waypointOrder, legs, sourceAddress, destinationAddress }) => {
acc.coordinates = [
...acc.coordinates,
...coordinates,
];
acc.distance += distance;
acc.duration += duration;
acc.sourceAddress = sourceAddress;
acc.destinationAddress = destinationAddress;
acc.fares = [
...acc.fares,
fare,
Expand All @@ -200,15 +201,21 @@ class MapViewDirections extends Component {
...acc.waypointOrder,
waypointOrder,
];

acc.steps = [
...acc.steps,
...steps,
];
return acc;
}, {
coordinates: [],
distance: 0,
duration: 0,
fares: [],
sourceAddress:'',
destinationAddress: '',
legs: [],
waypointOrder: [],
steps:[],
});

// Plot it out and call the onReady callback
Expand Down Expand Up @@ -273,6 +280,8 @@ class MapViewDirections extends Component {
),
fare: route.fare,
waypointOrder: route.waypoint_order,
sourceAddress: route.legs[0].start_address,
destinationAddress: route.legs[0].end_address,
legs: route.legs,
});

Expand Down