static double routeDistanceRemaining ( double legDistanceRemaining , int legIndex , DirectionsRoute directionsRoute ) { if ( directionsRoute . legs ( ) . size ( ) < 2 ) { return legDistanceRemaining ; } for ( int i = legIndex + 1 ; i < directionsRoute . legs ( ) . size ( ) ; i ++ ) { legDistanceRemaining += directionsRoute . legs ( ) . get ( i ) . distance ( ) ; } return legDistanceRemaining ; }
Takes in the leg distance remaining value already calculated and if additional legs need to be traversed along after the current one adds those distances and returns the new distance . Otherwise if the route only contains one leg or the users on the last leg this value will equal the leg distance remaining .