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