Search in sources :

Example 26 with DirectionsRoute

use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.

the class RouteUtilsTest method isArrivalEvent_returnsFalseWhenManeuverTypeIsArrival_andIsNotValidMetersRemaining.

@Test
public void isArrivalEvent_returnsFalseWhenManeuverTypeIsArrival_andIsNotValidMetersRemaining() throws Exception {
    DirectionsRoute aRoute = buildDirectionsRoute();
    int lastStepIndex = obtainLastStepIndex(aRoute);
    RouteProgress defaultRouteProgress = buildDefaultRouteProgress();
    RouteProgress theRouteProgress = defaultRouteProgress.toBuilder().stepIndex(lastStepIndex).legDistanceRemaining(100).build();
    boolean isArrivalEvent = RouteUtils.isArrivalEvent(theRouteProgress);
    assertFalse(isArrivalEvent);
}
Also used : DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest) Test(org.junit.Test)

Example 27 with DirectionsRoute

use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.

the class RouteUtilsTest method isArrivalEvent_returnsTrueWhenManeuverTypeIsArrival_andIsValidMetersRemaining.

@Test
public void isArrivalEvent_returnsTrueWhenManeuverTypeIsArrival_andIsValidMetersRemaining() throws Exception {
    DirectionsRoute aRoute = buildDirectionsRoute();
    int lastStepIndex = obtainLastStepIndex(aRoute);
    RouteProgress defaultRouteProgress = buildDefaultRouteProgress();
    RouteProgress theRouteProgress = defaultRouteProgress.toBuilder().stepDistanceRemaining(30).legDistanceRemaining(30).distanceRemaining(30).stepIndex(lastStepIndex).build();
    boolean isArrivalEvent = RouteUtils.isArrivalEvent(theRouteProgress);
    assertTrue(isArrivalEvent);
}
Also used : DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest) Test(org.junit.Test)

Example 28 with DirectionsRoute

use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.

the class RouteUtilsTest method isArrivalEvent_returnsFalseWhenManeuverTypeIsNotArrival_andIsNotValidMetersRemaining.

@Test
public void isArrivalEvent_returnsFalseWhenManeuverTypeIsNotArrival_andIsNotValidMetersRemaining() throws Exception {
    DirectionsRoute aRoute = buildDirectionsRoute();
    int lastStepIndex = obtainLastStepIndex(aRoute);
    RouteProgress defaultRouteProgress = buildDefaultRouteProgress();
    RouteProgress theRouteProgress = defaultRouteProgress.toBuilder().stepDistanceRemaining(200).legDistanceRemaining(300).distanceRemaining(300).stepIndex(lastStepIndex - 1).build();
    boolean isArrivalEvent = RouteUtils.isArrivalEvent(theRouteProgress);
    assertFalse(isArrivalEvent);
}
Also used : DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest) Test(org.junit.Test)

Example 29 with DirectionsRoute

use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.

the class RouteUtilsTest method obtainLastStepIndex.

private int obtainLastStepIndex(DirectionsRoute route) throws IOException {
    RouteLeg lastLeg = route.legs().get(route.legs().size() - 1);
    int lastStepIndex = lastLeg.steps().indexOf(lastLeg.steps().get(lastLeg.steps().size() - 1));
    return lastStepIndex;
}
Also used : RouteLeg(com.mapbox.api.directions.v5.models.RouteLeg)

Example 30 with DirectionsRoute

use of com.mapbox.api.directions.v5.models.DirectionsRoute in project mapbox-navigation-android by mapbox.

the class NavigationRouteProcessor method buildNewRouteProgress.

/**
 * Will take a given location update and create a new {@link RouteProgress}
 * based on our calculations of the distances remaining.
 * <p>
 * Also in charge of detecting if a step / leg has finished and incrementing the
 * indices if needed ({@link NavigationRouteProcessor#advanceIndices(MapboxNavigation)} handles
 * the decoding of the next step point list).
 *
 * @param mapboxNavigation for the current route / options
 * @param location         for step / leg / route distance remaining
 * @return new route progress along the route
 */
RouteProgress buildNewRouteProgress(MapboxNavigation mapboxNavigation, Location location) {
    DirectionsRoute directionsRoute = mapboxNavigation.getRoute();
    MapboxNavigationOptions options = mapboxNavigation.options();
    double completionOffset = options.maxTurnCompletionOffset();
    double maneuverZoneRadius = options.maneuverZoneRadius();
    checkNewRoute(mapboxNavigation);
    double stepDistanceRemaining = calculateStepDistanceRemaining(location, directionsRoute);
    boolean withinManeuverRadius = stepDistanceRemaining < maneuverZoneRadius;
    boolean bearingMatchesManeuver = checkBearingForStepCompletion(location, previousRouteProgress, stepDistanceRemaining, completionOffset);
    boolean forceIncreaseIndices = stepDistanceRemaining == 0 && !bearingMatchesManeuver;
    if ((bearingMatchesManeuver && withinManeuverRadius) || forceIncreaseIndices) {
        advanceIndices(mapboxNavigation);
        stepDistanceRemaining = calculateStepDistanceRemaining(location, directionsRoute);
    }
    int legIndex = indices.legIndex();
    int stepIndex = indices.stepIndex();
    double legDistanceRemaining = legDistanceRemaining(stepDistanceRemaining, legIndex, stepIndex, directionsRoute);
    double routeDistanceRemaining = routeDistanceRemaining(legDistanceRemaining, legIndex, directionsRoute);
    return RouteProgress.builder().stepDistanceRemaining(stepDistanceRemaining).legDistanceRemaining(legDistanceRemaining).distanceRemaining(routeDistanceRemaining).directionsRoute(directionsRoute).stepIndex(stepIndex).legIndex(legIndex).build();
}
Also used : DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute) Point(com.mapbox.geojson.Point)

Aggregations

DirectionsRoute (com.mapbox.api.directions.v5.models.DirectionsRoute)25 DirectionsResponse (com.mapbox.api.directions.v5.models.DirectionsResponse)14 Gson (com.google.gson.Gson)11 GsonBuilder (com.google.gson.GsonBuilder)11 BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)10 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)10 Test (org.junit.Test)10 RouteLeg (com.mapbox.api.directions.v5.models.RouteLeg)9 Before (org.junit.Before)7 Point (com.mapbox.geojson.Point)6 Location (android.location.Location)3 LegStep (com.mapbox.api.directions.v5.models.LegStep)3 LineString (com.mapbox.geojson.LineString)3 FasterRoute (com.mapbox.services.android.navigation.v5.route.FasterRoute)2 Feature (com.mapbox.services.commons.geojson.Feature)2 ArrayList (java.util.ArrayList)2 StepManeuver (com.mapbox.api.directions.v5.models.StepManeuver)1 NavigationRoute (com.mapbox.services.android.navigation.v5.navigation.NavigationRoute)1 LineString (com.mapbox.services.commons.geojson.LineString)1 Point (com.mapbox.services.commons.geojson.Point)1