Search in sources :

Example 41 with Point

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);
}
Also used : Point(com.mapbox.geojson.Point) RouteInformation(com.mapbox.services.android.navigation.v5.navigation.camera.RouteInformation) BaseTest(com.mapbox.services.android.navigation.ui.v5.BaseTest) Test(org.junit.Test)

Example 42 with Point

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());
}
Also used : Point(com.mapbox.geojson.Point) Feature(com.mapbox.geojson.Feature)

Example 43 with Point

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();
}
Also used : DirectionsRoute(com.mapbox.api.directions.v5.models.DirectionsRoute) Point(com.mapbox.geojson.Point)

Example 44 with Point

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;
}
Also used : Point(com.mapbox.geojson.Point)

Example 45 with Point

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);
    }
}
Also used : Random(java.util.Random) Point(com.mapbox.geojson.Point) Point(com.mapbox.geojson.Point)

Aggregations

Point (com.mapbox.geojson.Point)72 Test (org.junit.Test)31 BaseTest (com.mapbox.services.android.navigation.v5.BaseTest)29 Location (android.location.Location)18 RouteProgress (com.mapbox.services.android.navigation.v5.routeprogress.RouteProgress)17 LineString (com.mapbox.geojson.LineString)15 ArrayList (java.util.ArrayList)10 LegStep (com.mapbox.api.directions.v5.models.LegStep)9 LatLng (com.mapbox.mapboxsdk.geometry.LatLng)7 Feature (com.mapbox.geojson.Feature)4 NavigationRoute (com.mapbox.services.android.navigation.v5.navigation.NavigationRoute)4 DirectionsResponse (com.mapbox.api.directions.v5.models.DirectionsResponse)3 DirectionsRoute (com.mapbox.api.directions.v5.models.DirectionsRoute)3 CameraPosition (com.mapbox.mapboxsdk.camera.CameraPosition)3 LatLngBounds (com.mapbox.mapboxsdk.geometry.LatLngBounds)3 Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 RouteOptions (com.mapbox.api.directions.v5.models.RouteOptions)2 MarkerOptions (com.mapbox.mapboxsdk.annotations.MarkerOptions)2 BaseTest (com.mapbox.services.android.navigation.ui.v5.BaseTest)2