Search in sources :

Example 6 with Feature

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

Aggregations

Feature (com.mapbox.geojson.Feature)6 Point (com.mapbox.geojson.Point)4 LineString (com.mapbox.geojson.LineString)2 PointF (android.graphics.PointF)1 Location (android.location.Location)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 VectorSource (com.mapbox.mapboxsdk.style.sources.VectorSource)1 ArrayList (java.util.ArrayList)1