Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const formattedRespose = (leg) => {
- let result = {},
- legInfo = leg || response.routes[0].legs[0],
- basicInfo = {},
- resultantSteps = [],
- lastStep = {},
- nextPointInfo = {};
- basicInfo = {
- startAddress: legInfo.start_address,
- endAddress: legInfo.end_address,
- distance: legInfo.distance.text,
- duration: legInfo.duration.text,
- startTime: legInfo.departure_time.text,
- endTime: legInfo.arrival_time.text,
- };
- lastStep = {
- name: legInfo.end_address,
- time: legInfo.arrival_time.text,
- };
- nextPointInfo = {
- name: legInfo.start_address,
- time: legInfo.departure_time.text,
- };
- legInfo.steps.map((step, index) => {
- let stepObj = {},
- innerStepsHTML = [],
- transitDetails;
- stepObj.travelMode = step.travel_mode;
- if (step.travel_mode === 'WALKING') {
- stepObj.distance = step.distance.text;
- stepObj.duration = step.duration.text;
- stepObj.name = nextPointInfo.name;
- stepObj.time = nextPointInfo.time;
- stepObj.headSign = 'Walk';
- if (step.steps.length) {
- step.steps.map((innerStep, index) => {
- innerStepsHTML.push(innerStep.html_instructions);
- })
- stepObj.innerSteps = innerStepsHTML;
- }
- } else if (step.travel_mode === 'TRANSIT') {
- transitDetails = step.transit_details;
- stepObj.distance = step.distance.text;
- stepObj.duration = step.duration.text;
- stepObj.name = transitDetails.departure_stop.name;
- stepObj.time = transitDetails.departure_time.text;
- stepObj.numOfSteps = transitDetails.num_stops;
- stepObj.headSign = transitDetails.headsign;
- stepObj.lineInfo = transitDetails.line;
- nextPointInfo.name = transitDetails.arrival_stop.name;
- nextPointInfo.time = transitDetails.arrival_time.text;
- }
- resultantSteps[index] = stepObj;
- });
- resultantSteps.push(lastStep);
- return { steps: resultantSteps, basicInfo };
- };
- export default formattedRespose;
Add Comment
Please, Sign In to add comment