Search in sources :

Example 11 with LineString

use of com.mapbox.geojson.LineString in project mapbox-navigation-android by mapbox.

the class OffRouteDetector method movingAwayFromManeuver.

/**
 * Checks to see if the current point is moving away from the maneuver.
 * <p>
 * If the current point is farther away from the maneuver than the last point in the
 * stack, add it to the stack.
 * <p>
 * If the stack if >= 3 distances, return true to fire an off-route event as it
 * can be considered that the user is no longer going in the right direction.
 *
 * @param routeProgress             for the upcoming step maneuver
 * @param distancesAwayFromManeuver current stack of distances away
 * @param stepPoints                current step points being traveled along
 * @param currentPoint              to determine if moving away or not
 * @return true if moving away from maneuver, false if not
 */
private static boolean movingAwayFromManeuver(RouteProgress routeProgress, RingBuffer<Integer> distancesAwayFromManeuver, List<Point> stepPoints, Point currentPoint) {
    if (routeProgress.currentLegProgress().upComingStep() == null || stepPoints.isEmpty()) {
        return false;
    }
    LineString stepLineString = LineString.fromLngLats(stepPoints);
    Point maneuverPoint = stepPoints.get(stepPoints.size() - 1);
    Point userPointOnStep = (Point) TurfMisc.nearestPointOnLine(currentPoint, stepPoints).geometry();
    if (userPointOnStep == null || maneuverPoint.equals(userPointOnStep)) {
        return false;
    }
    LineString remainingStepLineString = TurfMisc.lineSlice(userPointOnStep, maneuverPoint, stepLineString);
    double userDistanceToManeuver = TurfMeasurement.length(remainingStepLineString, TurfConstants.UNIT_METERS);
    boolean hasDistances = !distancesAwayFromManeuver.isEmpty();
    boolean validOffRouteDistanceTraveled = hasDistances && distancesAwayFromManeuver.peekLast() - distancesAwayFromManeuver.peekFirst() < MINIMUM_BACKUP_DISTANCE_FOR_OFF_ROUTE;
    boolean exceedsManeuverDistancesThreshold = validOffRouteDistanceTraveled && distancesAwayFromManeuver.size() >= 3;
    if (exceedsManeuverDistancesThreshold) {
        // User's moving away from maneuver position, thus offRoute.
        return true;
    }
    if (distancesAwayFromManeuver.isEmpty()) {
        distancesAwayFromManeuver.push((int) userDistanceToManeuver);
    } else if (userDistanceToManeuver > distancesAwayFromManeuver.peek()) {
        distancesAwayFromManeuver.push((int) userDistanceToManeuver);
    } else {
        // If we get a descending distance, reset the counter
        distancesAwayFromManeuver.clear();
    }
    return false;
}
Also used : LineString(com.mapbox.geojson.LineString) Point(com.mapbox.geojson.Point)

Example 12 with LineString

use of com.mapbox.geojson.LineString in project mapbox-navigation-android by mapbox.

the class MockLocationEngine method calculateStepPoints.

/**
 * Instead of calculating all the points found in the entire route geometry, we go step by step as needed until the
 * route in complete. This resolves a memory issue when long routes are being mocked.
 *
 * @since 2.2.0
 */
private void calculateStepPoints() {
    LineString line = LineString.fromPolyline(route.legs().get(currentLeg).steps().get(currentStep).geometry(), Constants.PRECISION_6);
    increaseIndex();
    sliceRoute(line, distance);
    if (noisyGps) {
        addNoiseToRoute(distance);
    }
}
Also used : LineString(com.mapbox.geojson.LineString)

Example 13 with LineString

use of com.mapbox.geojson.LineString in project mapbox-navigation-android by mapbox.

the class BaseTest method createCoordinatesFromCurrentStep.

@NonNull
protected List<Point> createCoordinatesFromCurrentStep(RouteProgress progress) {
    LegStep currentStep = progress.currentLegProgress().currentStep();
    LineString lineString = LineString.fromPolyline(currentStep.geometry(), Constants.PRECISION_6);
    return lineString.coordinates();
}
Also used : LineString(com.mapbox.geojson.LineString) LegStep(com.mapbox.api.directions.v5.models.LegStep) NonNull(android.support.annotation.NonNull)

Example 14 with LineString

use of com.mapbox.geojson.LineString in project mapbox-navigation-android by mapbox.

the class ToleranceUtilsTest method dynamicRerouteDistanceTolerance_userJustPastTheIntersection.

@Test
public void dynamicRerouteDistanceTolerance_userJustPastTheIntersection() 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();
    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 15 with LineString

use of com.mapbox.geojson.LineString 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)

Aggregations

LineString (com.mapbox.geojson.LineString)19 Point (com.mapbox.geojson.Point)15 BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)9 Test (org.junit.Test)9 LegStep (com.mapbox.api.directions.v5.models.LegStep)5 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)5 Location (android.location.Location)2 Feature (com.mapbox.geojson.Feature)2 ArrayList (java.util.ArrayList)2 Handler (android.os.Handler)1 NonNull (android.support.annotation.NonNull)1 Nullable (android.support.annotation.Nullable)1 FeatureCollection (com.mapbox.geojson.FeatureCollection)1 Polygon (com.mapbox.geojson.Polygon)1 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)1 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)1 DataModel (com.mapbox.mapboxsdk.plugins.geojson.model.DataModel)1 MarkerData (com.mapbox.mapboxsdk.plugins.geojson.model.MarkerData)1 PolyData (com.mapbox.mapboxsdk.plugins.geojson.model.PolyData)1 RouteLegProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteLegProgress)1