Search in sources :

Example 36 with RouteProgress

use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.

the class ToleranceUtilsTest method dynamicRerouteDistanceTolerance_userFarAwayFromIntersection.

@Test
public void dynamicRerouteDistanceTolerance_userFarAwayFromIntersection() throws Exception {
    RouteProgress routeProgress = RouteProgress.builder().directionsRoute(response.routes().get(0)).legDistanceRemaining(0).distanceRemaining(0).stepIndex(0).legIndex(0).build();
    // Get a point on the route step which isn't close to an intersection.
    List<Point> stepPoints = PolylineUtils.decode(response.routes().get(0).geometry(), PRECISION_6);
    Point midPoint = TurfMeasurement.midpoint(stepPoints.get(0), stepPoints.get(1));
    double tolerance = ToleranceUtils.dynamicRerouteDistanceTolerance(midPoint, routeProgress);
    assertEquals(50.0, tolerance, DELTA);
}
Also used : Point(com.mapbox.geojson.Point) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 37 with RouteProgress

use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.

the class ToleranceUtilsTest method dynamicRerouteDistanceTolerance_userCloseToIntersection.

@Test
public void dynamicRerouteDistanceTolerance_userCloseToIntersection() throws Exception {
    RouteProgress routeProgress = RouteProgress.builder().directionsRoute(response.routes().get(0)).legDistanceRemaining(0).distanceRemaining(0).stepIndex(0).legIndex(0).build();
    double distanceToIntersection = response.routes().get(0).distance() - 39;
    LineString lineString = LineString.fromPolyline(response.routes().get(0).geometry(), Constants.PRECISION_6);
    Point closePoint = TurfMeasurement.along(lineString, distanceToIntersection, TurfConstants.UNIT_METERS);
    double tolerance = ToleranceUtils.dynamicRerouteDistanceTolerance(closePoint, routeProgress);
    assertEquals(25.0, tolerance, DELTA);
}
Also used : LineString(com.mapbox.geojson.LineString) Point(com.mapbox.geojson.Point) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 38 with RouteProgress

use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.

the class NavigationHelper method isUserOffRoute.

static boolean isUserOffRoute(NewLocationModel newLocationModel, RouteProgress routeProgress, OffRouteCallback callback) {
    MapboxNavigationOptions options = newLocationModel.mapboxNavigation().options();
    if (!options.enableOffRouteDetection()) {
        return false;
    }
    Location location = newLocationModel.location();
    OffRoute offRoute = newLocationModel.mapboxNavigation().getOffRouteEngine();
    setOffRouteDetectorCallback(offRoute, callback);
    return offRoute.isUserOffRoute(location, routeProgress, options);
}
Also used : OffRoute(com.mapbox.services.android.navigation.v5.offroute.OffRoute) Location(android.location.Location)

Example 39 with RouteProgress

use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.

the class NavigationService method onMilestoneTrigger.

/**
 * With each valid and successful rawLocation update, this will get called once the work on the
 * navigation engine thread has finished. Depending on whether or not a milestone gets triggered
 * or not, the navigation event dispatcher will be called to notify the developer.
 */
@Override
public void onMilestoneTrigger(List<Milestone> triggeredMilestones, RouteProgress routeProgress) {
    for (Milestone milestone : triggeredMilestones) {
        String instruction = buildInstructionString(routeProgress, milestone);
        mapboxNavigation.getEventDispatcher().onMilestoneEvent(routeProgress, instruction, milestone);
    }
}
Also used : Milestone(com.mapbox.services.android.navigation.v5.milestone.Milestone) NavigationHelper.buildInstructionString(com.mapbox.services.android.navigation.v5.navigation.NavigationHelper.buildInstructionString)

Example 40 with RouteProgress

use of com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress in project mapbox-navigation-android by mapbox.

the class FasterRouteDetector method validStepDurationRemaining.

private boolean validStepDurationRemaining(RouteProgress routeProgress) {
    RouteStepProgress currentStepProgress = routeProgress.currentLegProgress().currentStepProgress();
    // Current step duration remaining in seconds
    int currentStepDurationRemaining = (int) currentStepProgress.durationRemaining();
    return currentStepDurationRemaining > NAVIGATION_MEDIUM_ALERT_DURATION;
}
Also used : RouteStepProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteStepProgress)

Aggregations

BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)44 Test (org.junit.Test)44 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)39 Point (com.mapbox.geojson.Point)30 Location (android.location.Location)19 LineString (com.mapbox.geojson.LineString)12 DirectionsRoute (com.mapbox.api.directions.v5.models.DirectionsRoute)10 DirectionsResponse (com.mapbox.api.directions.v5.models.DirectionsResponse)3 LegStep (com.mapbox.api.directions.v5.models.LegStep)3 Milestone (com.mapbox.services.android.navigation.v5.milestone.Milestone)3 NavigationRoute (com.mapbox.services.android.navigation.v5.navigation.NavigationRoute)3 Context (android.content.Context)2 GsonBuilder (com.google.gson.GsonBuilder)2 RouteLeg (com.mapbox.api.directions.v5.models.RouteLeg)2 FasterRoute (com.mapbox.services.android.navigation.v5.route.FasterRoute)2 MetricsRouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.MetricsRouteProgress)2 RouteStepProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteStepProgress)2 DistanceUtils (com.mapbox.services.android.navigation.v5.utils.DistanceUtils)2 Date (java.util.Date)2 Ignore (org.junit.Ignore)2