Search in sources :

Example 46 with Point

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

the class MockLocationEngine method sliceRoute.

/*
   * Logic methods for getting the user points.
   */
/**
 * Interpolates the route into even points along the route and adds these to the points list.
 *
 * @param lineString our route geometry.
 * @param distance   the distance you want to interpolate the line by, by default we calculate the distance using the
 *                   speed variable.
 * @since 2.2.0
 */
private void sliceRoute(LineString lineString, double distance) {
    double distanceKm = TurfMeasurement.length(lineString, TurfConstants.UNIT_KILOMETERS);
    Timber.d("Route distance in km: %f", distanceKm);
    if (distanceKm <= 0) {
        return;
    }
    // Chop the line in small pieces
    for (double i = 0; i < distanceKm; i += distance) {
        Point point = TurfMeasurement.along(lineString, i, TurfConstants.UNIT_KILOMETERS);
        points.add(point);
    }
}
Also used : Point(com.mapbox.geojson.Point)

Example 47 with Point

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

the class MockLocationEngine method moveToLocation.

public void moveToLocation(Point point) {
    if (location == null) {
        return;
    }
    List<Point> pointList = new ArrayList<>();
    pointList.add(Point.fromLngLat(location.getLongitude(), location.getLatitude()));
    pointList.add(point);
    if (handler != null && runnable != null) {
        handler.removeCallbacks(runnable);
    }
    // Reset all variables
    handler = new Handler();
    points = new ArrayList<>();
    currentLeg = 0;
    currentStep = 0;
    // Calculate the distance which will always be consistent throughout the route.
    distance = calculateDistancePerSec();
    LineString route = LineString.fromLngLats(pointList);
    sliceRoute(route, distance);
    if (noisyGps) {
        addNoiseToRoute(distance);
    }
    runnable = new LocationUpdateRunnable();
    handler.postDelayed(runnable, delay);
}
Also used : LineString(com.mapbox.geojson.LineString) ArrayList(java.util.ArrayList) Handler(android.os.Handler) Point(com.mapbox.geojson.Point)

Example 48 with Point

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

the class RouteEngine method buildRouteRequestFromCurrentLocation.

@Nullable
public static NavigationRoute.Builder buildRouteRequestFromCurrentLocation(Point origin, Double bearing, RouteProgress progress) {
    RouteOptions options = progress.directionsRoute().routeOptions();
    NavigationRoute.Builder builder = NavigationRoute.builder().origin(origin, bearing, BEARING_TOLERANCE).routeOptions(options);
    List<Point> remainingWaypoints = RouteUtils.calculateRemainingWaypoints(progress);
    if (remainingWaypoints == null) {
        Timber.e("An error occurred fetching a new route");
        return null;
    }
    addDestination(remainingWaypoints, builder);
    addWaypoints(remainingWaypoints, builder);
    return builder;
}
Also used : Point(com.mapbox.geojson.Point) RouteOptions(com.mapbox.api.directions.v5.models.RouteOptions) NavigationRoute(com.mapbox.services.android.navigation.v5.navigation.NavigationRoute) Nullable(android.support.annotation.Nullable)

Example 49 with Point

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

the class SnapToRoute method snapLocationLatLng.

/**
 * Logic used to snap the users location coordinates to the closest position along the current
 * step.
 *
 * @param location        the raw location
 * @param stepCoordinates the list of step geometry coordinates
 * @return the altered user location
 * @since 0.4.0
 */
private static Location snapLocationLatLng(Location location, List<Point> stepCoordinates) {
    Location snappedLocation = new Location(location);
    Point locationToPoint = Point.fromLngLat(location.getLongitude(), location.getLatitude());
    // Point on the LineString.
    if (stepCoordinates.size() > 1) {
        Feature feature = TurfMisc.nearestPointOnLine(locationToPoint, stepCoordinates);
        Point point = ((Point) feature.geometry());
        snappedLocation.setLongitude(point.longitude());
        snappedLocation.setLatitude(point.latitude());
    }
    return snappedLocation;
}
Also used : Point(com.mapbox.geojson.Point) Feature(com.mapbox.geojson.Feature) Location(android.location.Location)

Example 50 with Point

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

the class RouteUtils method createFirstLocationFromRoute.

/**
 * If navigation begins, a location update is sometimes needed to force a
 * progress change update as soon as navigation is started.
 * <p>
 * This method creates a location update from the first coordinate (origin) that created
 * the route.
 *
 * @param route with list of coordinates
 * @return {@link Location} from first coordinate
 * @since 0.10.0
 */
public static Location createFirstLocationFromRoute(DirectionsRoute route) {
    List<Point> coordinates = route.routeOptions().coordinates();
    Point origin = coordinates.get(FIRST_COORDINATE);
    Location forcedLocation = new Location(FORCED_LOCATION);
    forcedLocation.setLatitude(origin.latitude());
    forcedLocation.setLongitude(origin.longitude());
    return forcedLocation;
}
Also used : Point(com.mapbox.geojson.Point) Location(android.location.Location)

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