Search in sources :

Example 1 with LegStep

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

the class OffRouteDetectorTest method isUserOffRoute_AssertFalseTwoUpdatesAwayFromManeuverThenOneTowards.

@Test
public void isUserOffRoute_AssertFalseTwoUpdatesAwayFromManeuverThenOneTowards() throws Exception {
    RouteProgress routeProgress = buildDefaultRouteProgress();
    LegStep currentStep = routeProgress.currentLegProgress().currentStep();
    LineString lineString = LineString.fromPolyline(currentStep.geometry(), Constants.PRECISION_6);
    List<Point> coordinates = lineString.coordinates();
    Location firstLocationUpdate = buildDefaultLocationUpdate(-77.0339782574523, 38.89993519985637);
    offRouteDetector.isUserOffRoute(firstLocationUpdate, routeProgress, options);
    Point lastPointInCurrentStep = coordinates.remove(coordinates.size() - 1);
    Location secondLocationUpdate = buildDefaultLocationUpdate(lastPointInCurrentStep.longitude(), lastPointInCurrentStep.latitude());
    boolean isUserOffRouteFirstTry = offRouteDetector.isUserOffRoute(secondLocationUpdate, routeProgress, options);
    assertFalse(isUserOffRouteFirstTry);
    Point secondLastPointInCurrentStep = coordinates.remove(coordinates.size() - 1);
    Location thirdLocationUpdate = buildDefaultLocationUpdate(secondLastPointInCurrentStep.longitude(), secondLastPointInCurrentStep.latitude());
    boolean isUserOffRouteSecondTry = offRouteDetector.isUserOffRoute(thirdLocationUpdate, routeProgress, options);
    assertFalse(isUserOffRouteSecondTry);
    Location fourthLocationUpdate = buildDefaultLocationUpdate(lastPointInCurrentStep.longitude(), lastPointInCurrentStep.latitude());
    boolean isUserOffRouteThirdTry = offRouteDetector.isUserOffRoute(fourthLocationUpdate, routeProgress, options);
    assertFalse(isUserOffRouteThirdTry);
}
Also used : LineString(com.mapbox.geojson.LineString) Point(com.mapbox.geojson.Point) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) LegStep(com.mapbox.api.directions.v5.models.LegStep) Location(android.location.Location) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 2 with LegStep

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

the class OffRouteDetectorTest method isUserOffRoute_AssertTrueWhenOnRouteButMovingAwayFromManeuver.

@Test
public void isUserOffRoute_AssertTrueWhenOnRouteButMovingAwayFromManeuver() throws Exception {
    RouteProgress routeProgress = buildDefaultRouteProgress();
    LegStep currentStep = routeProgress.currentLegProgress().currentStep();
    LineString lineString = LineString.fromPolyline(currentStep.geometry(), Constants.PRECISION_6);
    List<Point> coordinates = lineString.coordinates();
    Location firstLocationUpdate = buildDefaultLocationUpdate(-77.0339782574523, 38.89993519985637);
    offRouteDetector.isUserOffRoute(firstLocationUpdate, routeProgress, options);
    Point lastPointInCurrentStep = coordinates.remove(coordinates.size() - 1);
    Location secondLocationUpdate = buildDefaultLocationUpdate(lastPointInCurrentStep.longitude(), lastPointInCurrentStep.latitude());
    boolean isUserOffRouteFirstTry = offRouteDetector.isUserOffRoute(secondLocationUpdate, routeProgress, options);
    assertFalse(isUserOffRouteFirstTry);
    Point secondLastPointInCurrentStep = coordinates.remove(coordinates.size() - 1);
    Location thirdLocationUpdate = buildDefaultLocationUpdate(secondLastPointInCurrentStep.longitude(), secondLastPointInCurrentStep.latitude());
    boolean isUserOffRouteSecondTry = offRouteDetector.isUserOffRoute(thirdLocationUpdate, routeProgress, options);
    assertFalse(isUserOffRouteSecondTry);
    Point thirdLastPointInCurrentStep = coordinates.remove(coordinates.size() - 1);
    Location fourthLocationUpdate = buildDefaultLocationUpdate(thirdLastPointInCurrentStep.longitude(), thirdLastPointInCurrentStep.latitude());
    boolean isUserOffRouteThirdTry = offRouteDetector.isUserOffRoute(fourthLocationUpdate, routeProgress, options);
    assertFalse(isUserOffRouteThirdTry);
    Point fourthLastPointInCurrentStep = coordinates.remove(coordinates.size() - 1);
    Location fifthLocationUpdate = buildDefaultLocationUpdate(fourthLastPointInCurrentStep.longitude(), fourthLastPointInCurrentStep.latitude());
    boolean isUserOffRouteFourthTry = offRouteDetector.isUserOffRoute(fifthLocationUpdate, routeProgress, options);
    assertFalse(isUserOffRouteFourthTry);
    Point fifthLastPointInCurrentStep = coordinates.remove(coordinates.size() - 1);
    Location sixthLocationUpdate = buildDefaultLocationUpdate(fifthLastPointInCurrentStep.longitude(), fifthLastPointInCurrentStep.latitude());
    boolean isUserOffRouteFifthTry = offRouteDetector.isUserOffRoute(sixthLocationUpdate, routeProgress, options);
    assertTrue(isUserOffRouteFifthTry);
}
Also used : LineString(com.mapbox.geojson.LineString) Point(com.mapbox.geojson.Point) RouteProgress(com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress) LegStep(com.mapbox.api.directions.v5.models.LegStep) Location(android.location.Location) Test(org.junit.Test) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest)

Example 3 with LegStep

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

the class NavigationHelper method stepDistanceRemaining.

/**
 * Calculates the distance remaining in the step from the current users snapped position, to the
 * next maneuver position.
 */
static double stepDistanceRemaining(Point snappedPosition, int legIndex, int stepIndex, DirectionsRoute directionsRoute, List<Point> coordinates) {
    List<LegStep> steps = directionsRoute.legs().get(legIndex).steps();
    Point nextManeuverPosition = nextManeuverPosition(stepIndex, steps, coordinates);
    LineString lineString = LineString.fromPolyline(steps.get(stepIndex).geometry(), Constants.PRECISION_6);
    // position or the linestring coordinate size is less than 2,the distance remaining is zero.
    if (snappedPosition.equals(nextManeuverPosition) || lineString.coordinates().size() < 2) {
        return 0;
    }
    LineString slicedLine = TurfMisc.lineSlice(snappedPosition, nextManeuverPosition, lineString);
    return TurfMeasurement.length(slicedLine, TurfConstants.UNIT_METERS);
}
Also used : LineString(com.mapbox.geojson.LineString) Point(com.mapbox.geojson.Point) LegStep(com.mapbox.api.directions.v5.models.LegStep)

Example 4 with LegStep

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

the class OffRouteDetector method isUserOffRoute.

/**
 * Method in charge of running a series of test based on the device current location
 * and the user progress along the route.
 * <p>
 * Test #1:
 * Valid or invalid off-route.  An off-route check can only continue if the device has received
 * at least 1 location update (for comparison) and the user has traveled passed
 * the {@link MapboxNavigationOptions#minimumDistanceBeforeRerouting()} checked against the last re-route location.
 * <p>
 * Test #2:
 * Distance from the step. This test is checked against the max of the dynamic rerouting tolerance or the
 * accuracy based tolerance. If this test passes, this method then also checks if there have been &gt;= 3
 * location updates moving away from the maneuver point. If false, this method will return false early.
 * <p>
 * Test #3:
 * Checks if the user is close the upcoming step.  At this point, the user is considered off-route.
 * But, if the location update is within the {@link MapboxNavigationOptions#maneuverZoneRadius()} of the
 * upcoming step, this method will return false as well as send fire {@link OffRouteCallback#onShouldIncreaseIndex()}
 * to let the <tt>NavigationEngine</tt> know that the
 * step index should be increased on the next location update.
 *
 * @return true if the users off-route, else false.
 * @since 0.2.0
 */
@Override
public boolean isUserOffRoute(Location location, RouteProgress routeProgress, MapboxNavigationOptions options) {
    if (!validOffRoute(location, options)) {
        return false;
    }
    Point currentPoint = Point.fromLngLat(location.getLongitude(), location.getLatitude());
    // Get distance from the current step to future point
    LegStep currentStep = routeProgress.currentLegProgress().currentStep();
    double distanceFromCurrentStep = userTrueDistanceFromStep(currentPoint, currentStep);
    // Create off-route radius from the max of our dynamic or accuracy based tolerances
    double offRouteRadius = createOffRouteRadius(location, routeProgress, options, currentPoint);
    // Off route if this distance is greater than our offRouteRadius
    boolean isOffRoute = distanceFromCurrentStep > offRouteRadius;
    // If not offRoute at this point, do not continue with remaining logic
    if (!isOffRoute) {
        // moving away from the maneuver.
        return isMovingAwayFromManeuver(location, routeProgress, distancesAwayFromManeuver, currentPoint);
    }
    // If the user is considered off-route at this point, but they are close to the upcoming step,
    // do not send an off-route event and increment the step index to the upcoming step
    LegStep upComingStep = routeProgress.currentLegProgress().upComingStep();
    if (closeToUpcomingStep(options, callback, currentPoint, upComingStep)) {
        return false;
    }
    // All checks have run, return true
    updateLastReroutePoint(location);
    return true;
}
Also used : Point(com.mapbox.geojson.Point) LegStep(com.mapbox.api.directions.v5.models.LegStep)

Example 5 with LegStep

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

the class MeasurementUtilsTest method userTrueDistanceFromStep_returnsZeroWhenCurrentStepAndPointEqualSame.

@Test
public void userTrueDistanceFromStep_returnsZeroWhenCurrentStepAndPointEqualSame() {
    Point futurePoint = Point.fromLngLat(-95.367697, 29.758938);
    List<Point> geometryPoints = new ArrayList<>();
    geometryPoints.add(futurePoint);
    double[] rawLocation = { 0, 0 };
    LegStep step = getLegStep(rawLocation, geometryPoints);
    double distance = MeasurementUtils.userTrueDistanceFromStep(futurePoint, step);
    assertEquals(0d, distance, DELTA);
}
Also used : ArrayList(java.util.ArrayList) Point(com.mapbox.geojson.Point) LegStep(com.mapbox.api.directions.v5.models.LegStep) BaseTest(com.mapbox.services.android.navigation.v5.BaseTest) Test(org.junit.Test)

Aggregations

LegStep (com.mapbox.api.directions.v5.models.LegStep)18 Point (com.mapbox.geojson.Point)9 LineString (com.mapbox.geojson.LineString)5 BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)5 ArrayList (java.util.ArrayList)5 Test (org.junit.Test)5 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)3 Location (android.location.Location)2 RouteLeg (com.mapbox.api.directions.v5.models.RouteLeg)2 NonNull (android.support.annotation.NonNull)1 SpannableString (android.text.SpannableString)1 BannerInstructions (com.mapbox.api.directions.v5.models.BannerInstructions)1 DirectionsRoute (com.mapbox.api.directions.v5.models.DirectionsRoute)1 IntersectionLanes (com.mapbox.api.directions.v5.models.IntersectionLanes)1 StepIntersection (com.mapbox.api.directions.v5.models.StepIntersection)1 StepManeuver (com.mapbox.api.directions.v5.models.StepManeuver)1 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)1 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)1 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)1