use of com.mapbox.geojson.LineString 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.LineString in project mapbox-navigation-android by mapbox.
the class OffRouteDetectorTest method setupStepPoints.
private void setupStepPoints(OffRouteDetector offRouteDetector) throws Exception {
RouteProgress routeProgress = buildDefaultRouteProgress();
LegStep currentStep = routeProgress.currentLegProgress().currentStep();
LineString lineString = LineString.fromPolyline(currentStep.geometry(), Constants.PRECISION_6);
List<Point> stepPoints = lineString.coordinates();
offRouteDetector.updateStepPoints(stepPoints);
}
use of com.mapbox.geojson.LineString in project mapbox-navigation-android by mapbox.
the class RouteStepProgressTest method distanceRemaining_equalsCorrectValueAtIntervals.
@Test
public void distanceRemaining_equalsCorrectValueAtIntervals() {
LineString lineString = LineString.fromPolyline(firstStep.geometry(), Constants.PRECISION_6);
double stepDistance = TurfMeasurement.length(lineString, TurfConstants.UNIT_METERS);
// meters
double stepSegments = 5;
// Chop the line in small pieces
for (double i = 0; i < stepDistance; i += stepSegments) {
Point point = TurfMeasurement.along(lineString, i, TurfConstants.UNIT_METERS);
if (point.equals(route.legs().get(0).steps().get(1).maneuver().location())) {
return;
}
LineString slicedLine = TurfMisc.lineSlice(point, route.legs().get(0).steps().get(1).maneuver().location(), lineString);
double distance = TurfMeasurement.length(slicedLine, TurfConstants.UNIT_METERS);
RouteProgress routeProgress = RouteProgress.builder().stepDistanceRemaining(distance).legDistanceRemaining(firstLeg.distance()).distanceRemaining(route.distance()).directionsRoute(route).stepIndex(0).legIndex(0).build();
RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();
assertEquals(distance, routeStepProgress.distanceRemaining(), BaseTest.DELTA);
}
}
use of com.mapbox.geojson.LineString in project mapbox-navigation-android by mapbox.
the class RouteStepProgressTest method getDurationRemaining_equalsCorrectValueAtIntervals.
@Test
public void getDurationRemaining_equalsCorrectValueAtIntervals() {
LineString lineString = LineString.fromPolyline(firstStep.geometry(), Constants.PRECISION_6);
// meters
double stepSegments = 5;
// Chop the line in small pieces
for (double i = 0; i < firstStep.distance(); i += stepSegments) {
Point point = TurfMeasurement.along(lineString, i, TurfConstants.UNIT_METERS);
LineString slicedLine = TurfMisc.lineSlice(point, route.legs().get(0).steps().get(1).maneuver().location(), lineString);
double distance = TurfMeasurement.length(slicedLine, TurfConstants.UNIT_METERS);
RouteProgress routeProgress = RouteProgress.builder().stepDistanceRemaining(distance).legDistanceRemaining(firstLeg.distance()).distanceRemaining(route.distance()).directionsRoute(route).stepIndex(0).legIndex(0).build();
RouteStepProgress routeStepProgress = routeProgress.currentLegProgress().currentStepProgress();
double fractionRemaining = (firstStep.distance() - distance) / firstStep.distance();
assertEquals((1.0 - fractionRemaining) * firstStep.duration(), routeStepProgress.durationRemaining(), BaseTest.LARGE_DELTA);
}
}
Aggregations