use of com.mapbox.api.directions.v5.models.RouteLeg in project mapbox-navigation-android by mapbox.
the class FasterRouteDetector method isFasterRoute.
@Override
public boolean isFasterRoute(DirectionsResponse response, RouteProgress routeProgress) {
if (validRouteResponse(response)) {
double currentDurationRemaining = routeProgress.durationRemaining();
DirectionsRoute newRoute = response.routes().get(0);
if (hasLegs(newRoute)) {
// Extract the first leg
RouteLeg routeLeg = newRoute.legs().get(0);
if (hasAtLeastTwoSteps(routeLeg)) {
// Extract the first two steps
LegStep firstStep = routeLeg.steps().get(0);
LegStep secondStep = routeLeg.steps().get(1);
// Check for valid first and second steps of the new route
if (!validFirstStep(firstStep) || !validSecondStep(secondStep, routeProgress)) {
return false;
}
}
}
// New route must be at least 10% faster
if (newRoute.duration() <= (0.9 * currentDurationRemaining)) {
return true;
}
}
return false;
}
use of com.mapbox.api.directions.v5.models.RouteLeg in project mapbox-navigation-android by mapbox.
the class MetricsRouteProgress method retrieveRouteDestination.
private Point retrieveRouteDestination(DirectionsRoute route) {
RouteLeg lastLeg = route.legs().get(route.legs().size() - 1);
LegStep lastStep = lastLeg.steps().get(lastLeg.steps().size() - 1);
StepManeuver finalManuever = lastStep.maneuver();
if (finalManuever.location() != null) {
return finalManuever.location();
}
return Point.fromLngLat(0d, 0d);
}
use of com.mapbox.api.directions.v5.models.RouteLeg in project mapbox-navigation-android by mapbox.
the class RouteLegProgress method create.
/**
* Constructor for the route leg progress information.
*
* @param routeLeg the current {@link RouteLeg} the user is traversing along
* @param stepIndex the current step index the user is on
* @param legDistanceRemaining the leg distance remaining which is calculated in navigation engine
* @param stepDistanceRemaining the step distance remaining which is calculated in navigation engine
* @since 0.1.0
*/
static RouteLegProgress create(RouteLeg routeLeg, int stepIndex, double legDistanceRemaining, double stepDistanceRemaining) {
LegStep nextStep = stepIndex == (routeLeg.steps().size() - 1) ? null : routeLeg.steps().get(stepIndex + 1);
RouteStepProgress stepProgress = RouteStepProgress.create(routeLeg.steps().get(stepIndex), nextStep, stepDistanceRemaining);
return new AutoValue_RouteLegProgress(routeLeg, stepIndex, legDistanceRemaining, stepProgress);
}
use of com.mapbox.api.directions.v5.models.RouteLeg in project mapbox-navigation-android by mapbox.
the class RouteUtils method isLastLeg.
/**
* Looks at the current {@link RouteProgress} list of legs and
* checks if the current leg is the last leg.
*
* @param routeProgress the current route progress
* @return true if last leg, false if not
* @since 0.8.0
*/
public static boolean isLastLeg(RouteProgress routeProgress) {
List<RouteLeg> legs = routeProgress.directionsRoute().legs();
RouteLeg currentLeg = routeProgress.currentLeg();
return currentLeg.equals(legs.get(legs.size() - 1));
}
use of com.mapbox.api.directions.v5.models.RouteLeg in project mapbox-navigation-android by mapbox.
the class RouteProgressTest method multiLeg_getFractionTraveled_equalsCorrectValueAtIntervals.
// TODO check fut
@Test
public void multiLeg_getFractionTraveled_equalsCorrectValueAtIntervals() {
// Chop the line in small pieces
for (RouteLeg leg : multiLegRoute.legs()) {
for (int step = 0; step < leg.steps().size(); step++) {
RouteProgress routeProgress = RouteProgress.builder().stepDistanceRemaining(multiLegRoute.legs().get(0).steps().get(0).distance()).legDistanceRemaining(multiLegRoute.legs().get(0).distance()).distanceRemaining(multiLegRoute.distance()).directionsRoute(multiLegRoute).stepIndex(step).legIndex(0).build();
float fractionRemaining = (float) (routeProgress.distanceTraveled() / multiLegRoute.distance());
assertEquals(fractionRemaining, routeProgress.fractionTraveled(), BaseTest.LARGE_DELTA);
}
}
}
Aggregations