use of com.mapbox.geojson.Point 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);
}
use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.
the class OffRouteDetector method validOffRoute.
/**
* Method to check if the user has passed either the set (in {@link MapboxNavigationOptions})
* minimum amount of seconds or minimum amount of meters since the last reroute.
* <p>
* If the user is above both thresholds, then the off-route can proceed. Otherwise, ignore.
*
* @param location current location from engine
* @param options for second (default 3) / distance (default 50m) minimums
* @return true if valid, false if not
*/
private boolean validOffRoute(Location location, MapboxNavigationOptions options) {
// Check if minimum amount of distance has been passed since last reroute
Point currentPoint = Point.fromLngLat(location.getLongitude(), location.getLatitude());
double distanceFromLastReroute = 0d;
if (lastReroutePoint != null) {
distanceFromLastReroute = TurfMeasurement.distance(lastReroutePoint, currentPoint, TurfConstants.UNIT_METERS);
} else {
// If null, this is our first update - set the last reroute point to the given location
updateLastReroutePoint(location);
}
return distanceFromLastReroute > options.minimumDistanceBeforeRerouting();
}
use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.
the class ToleranceUtils method dynamicRerouteDistanceTolerance.
public static double dynamicRerouteDistanceTolerance(Point snappedPoint, RouteProgress routeProgress) {
List<StepIntersection> intersections = routeProgress.currentLegProgress().currentStepProgress().intersections();
List<Point> intersectionsPoints = new ArrayList<>();
for (StepIntersection intersection : intersections) {
intersectionsPoints.add(intersection.location());
}
Point closestIntersection = TurfClassification.nearestPoint(snappedPoint, intersectionsPoints);
if (closestIntersection.equals(snappedPoint)) {
return NavigationConstants.MINIMUM_DISTANCE_BEFORE_REROUTING;
}
double distanceToNextIntersection = TurfMeasurement.distance(snappedPoint, closestIntersection, TurfConstants.UNIT_METERS);
if (distanceToNextIntersection <= NavigationConstants.MANEUVER_ZONE_RADIUS) {
return NavigationConstants.MINIMUM_DISTANCE_BEFORE_REROUTING / 2;
}
return NavigationConstants.MINIMUM_DISTANCE_BEFORE_REROUTING;
}
use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.
the class NavigationTelemetry method updateLastRerouteEvent.
private void updateLastRerouteEvent(DirectionsRoute newDirectionsRoute) {
if (!queuedRerouteEvents.isEmpty()) {
RerouteEvent rerouteEvent = queuedRerouteEvents.get(queuedRerouteEvents.size() - 1);
List<Point> geometryPositions = PolylineUtils.decode(newDirectionsRoute.geometry(), Constants.PRECISION_6);
PolylineUtils.encode(geometryPositions, Constants.PRECISION_5);
rerouteEvent.setNewRouteGeometry(PolylineUtils.encode(geometryPositions, Constants.PRECISION_5));
int newDistanceRemaining = newDirectionsRoute.distance() == null ? 0 : newDirectionsRoute.distance().intValue();
rerouteEvent.setNewDistanceRemaining(newDistanceRemaining);
int newDurationRemaining = newDirectionsRoute.duration() == null ? 0 : newDirectionsRoute.duration().intValue();
rerouteEvent.setNewDurationRemaining(newDurationRemaining);
}
}
use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.
the class SimpleCamera method target.
@Override
public Point target(RouteInformation routeInformation) {
double lng;
double lat;
Point targetPoint = null;
if (routeInformation.route() != null) {
setupLineStringAndBearing(routeInformation.route());
lng = lineString.coordinates().get(0).longitude();
lat = lineString.coordinates().get(0).latitude();
return Point.fromLngLat(lng, lat);
} else if (routeInformation.location() != null) {
lng = routeInformation.location().getLongitude();
lat = routeInformation.location().getLatitude();
targetPoint = Point.fromLngLat(lng, lat);
}
return targetPoint;
}
Aggregations