use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.
the class DynamicCameraTest method onInformationFromRoute_engineCreatesCorrectTarget.
@Test
public void onInformationFromRoute_engineCreatesCorrectTarget() throws Exception {
RouteInformation routeInformation = RouteInformation.create(buildDirectionsRoute(), null, null);
Point target = cameraEngine.target(routeInformation);
double lng = target.longitude();
assertEquals(-122.416686, lng);
double lat = target.latitude();
assertEquals(37.783425, lat);
}
use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.
the class NavigationHelper method userSnappedToRoutePosition.
/**
* Takes in a raw location, converts it to a point, and snaps it to the closest point along the
* route. This is isolated as separate logic from the snap logic provided because we will always
* need to snap to the route in order to get the most accurate information.
*/
static Point userSnappedToRoutePosition(Location location, List<Point> coordinates) {
if (coordinates.size() < 2) {
return Point.fromLngLat(location.getLongitude(), location.getLatitude());
}
Point locationToPoint = Point.fromLngLat(location.getLongitude(), location.getLatitude());
// Uses Turf's pointOnLine, which takes a Point and a LineString to calculate the closest
// Point on the LineString.
Feature feature = TurfMisc.nearestPointOnLine(locationToPoint, coordinates);
return ((Point) feature.geometry());
}
use of com.mapbox.geojson.Point 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();
}
use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.
the class LocationValidator method isValidVelocity.
/**
* Calculates the velocity between the new location update and the last update
* that has been stored.
* <p>
* Average velocity = distance traveled over time (distance / time).
*
* @param location new location received
* @param timeSinceLastValidUpdate in millis, how long it has been since the new and last update
* @return true if valid velocity, false otherwise
*/
private boolean isValidVelocity(@NonNull Location location, long timeSinceLastValidUpdate) {
Point currentPoint = Point.fromLngLat(location.getLongitude(), location.getLatitude());
Point previousValidPoint = Point.fromLngLat(lastValidLocation.getLongitude(), lastValidLocation.getLatitude());
double distanceInMeters = TurfMeasurement.distance(previousValidPoint, currentPoint, TurfConstants.UNIT_METERS);
double velocityInMetersPerSecond = distanceInMeters / (timeSinceLastValidUpdate / ONE_SECOND_IN_MILLIS);
return velocityInMetersPerSecond <= locationVelocityInMetersPerSecondThreshold;
}
use of com.mapbox.geojson.Point in project mapbox-navigation-android by mapbox.
the class MockLocationEngine method addNoiseToRoute.
/**
* Emulate a noisy route using this method. Note that some points might not be noisy if the random value produced
* equals 0.
*
* @since 2.2.0
*/
private void addNoiseToRoute(double distance) {
// End point will always match the given route (no noise will be added)
for (int i = 0; i < points.size() - 1; i++) {
double bearing = TurfMeasurement.bearing(points.get(i), points.get(i + 1));
Random random = new Random();
bearing = random.nextInt(15 - -15) + bearing;
Point point = TurfMeasurement.destination(points.get(i), distance, bearing, TurfConstants.UNIT_KILOMETERS);
points.set(i, point);
}
}
Aggregations