Search in sources :

Example 6 with RouteLeg

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;
}
Also used : DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute) RouteLeg(com.mapbox.api.directions.v5.models.RouteLeg) LegStep(com.mapbox.api.directions.v5.models.LegStep)

Example 7 with RouteLeg

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);
}
Also used : StepManeuver(com.mapbox.api.directions.v5.models.StepManeuver) RouteLeg(com.mapbox.api.directions.v5.models.RouteLeg) LegStep(com.mapbox.api.directions.v5.models.LegStep)

Example 8 with RouteLeg

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);
}
Also used : LegStep(com.mapbox.api.directions.v5.models.LegStep)

Example 9 with RouteLeg

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));
}
Also used : RouteLeg(com.mapbox.api.directions.v5.models.RouteLeg)

Example 10 with RouteLeg

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);
        }
    }
}
Also used : RouteLeg(com.mapbox.api.directions.v5.models.RouteLeg) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Aggregations

RouteLeg (com.mapbox.api.directions.v5.models.RouteLeg)10 LegStep (com.mapbox.api.directions.v5.models.LegStep)3 BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)2 Feature (com.mapbox.services.commons.geojson.Feature)2 Test (org.junit.Test)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 DirectionsResponse (com.mapbox.api.directions.v5.models.DirectionsResponse)1 DirectionsRoute (com.mapbox.api.directions.v5.models.DirectionsRoute)1 StepManeuver (com.mapbox.api.directions.v5.models.StepManeuver)1 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)1 LineString (com.mapbox.services.commons.geojson.LineString)1 Point (com.mapbox.services.commons.geojson.Point)1 ArrayList (java.util.ArrayList)1 Before (org.junit.Before)1