Select to view content in your preferred language

Calculate several routes' totalTime using 'solve' function in RouteTask

1974
1
Jump to solution
02-24-2016 06:16 AM
LinQing
Deactivated User

Hello everybody,

I am trying to get the travel time of several routes using the methods and functions in 'RouteTask' but I met a problem. Here are my codes.

function Judge(){
    var combination=get_Combination();  //get_Combination() is a function that can return the different combinations of stops
    for(var h=0;h<combination.length;h++){
          clearStops(); // clear the stops set
          add(combination);  // add the stop combinations in array into the stops set
          solve_Route();
     }    
}

the solve_Route() function is,

function solve_Route() {
    routeTask.solve(routeParams).then(function(results){
        console.log(results.routeResults[0].directions.totalTime);
    });

My testing data has 3 stops and there are 4 combinations in total. Except the combination that only has one stop.

The problem is the order of travel time is different every time as follow. It seems like the order is random.

I don't know what the order depends on. That's to say I don't know each time corresponds to which route. And I need to know this cause I still need to use the time do some judgement. So any suggestions I will be so appreciated.

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
LinQing
Deactivated User

I got a solution. We can specify the 'RouteParameters.returnStops' as true, so there will be the stops of current route in each routeResult .Just like this.

In this way, we can know which route the time represents for.

View solution in original post

1 Reply
LinQing
Deactivated User

I got a solution. We can specify the 'RouteParameters.returnStops' as true, so there will be the stops of current route in each routeResult .Just like this.

In this way, we can know which route the time represents for.