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;
}
Aggregations