use of com.mapbox.api.directions.v5.models.LegStep in project mapbox-navigation-android by mapbox.
the class MeasurementUtilsTest method userTrueDistanceFromStep_onePointStepGeometryWithDifferentRawPoint.
@Test
public void userTrueDistanceFromStep_onePointStepGeometryWithDifferentRawPoint() {
Point futurePoint = Point.fromLngLat(-95.3676974, 29.7589382);
List<Point> geometryPoints = new ArrayList<>();
geometryPoints.add(Point.fromLngLat(-95.8427, 29.7757));
geometryPoints.add(futurePoint);
double[] rawLocation = { 0, 0 };
LegStep step = getLegStep(rawLocation, geometryPoints);
double distance = MeasurementUtils.userTrueDistanceFromStep(futurePoint, step);
assertEquals(0.04457271773629306d, distance, DELTA);
}
use of com.mapbox.api.directions.v5.models.LegStep in project mapbox-navigation-android by mapbox.
the class MapboxNavigationNotification method updateNotificationViews.
/**
* With each location update and new routeProgress, the notification is checked and updated if any
* information has changed.
*
* @param routeProgress the latest RouteProgress object
*/
private void updateNotificationViews(RouteProgress routeProgress) {
// Instruction
updateInstructionText(routeProgress.currentLegProgress().currentStep());
// Distance
updateDistanceText(routeProgress);
// Arrival Time
updateArrivalTime(routeProgress);
// Get upcoming step for maneuver image - current step if null
LegStep step = routeProgress.currentLegProgress().upComingStep() != null ? routeProgress.currentLegProgress().upComingStep() : routeProgress.currentLegProgress().currentStep();
// Maneuver Image
updateManeuverImage(step);
notificationManager.notify(NAVIGATION_NOTIFICATION_ID, notificationBuilder.build());
}
use of com.mapbox.api.directions.v5.models.LegStep in project mapbox-navigation-android by mapbox.
the class FasterRouteDetector method isFasterRoute.
@Override
public boolean isFasterRoute(DirectionsResponse response, RouteProgress routeProgress) {
if (validRouteResponse(response)) {
double currentDurationRemaining = routeProgress.durationRemaining();
DirectionsRoute newRoute = response.routes().get(0);
if (hasLegs(newRoute)) {
// Extract the first leg
RouteLeg routeLeg = newRoute.legs().get(0);
if (hasAtLeastTwoSteps(routeLeg)) {
// Extract the first two steps
LegStep firstStep = routeLeg.steps().get(0);
LegStep secondStep = routeLeg.steps().get(1);
// Check for valid first and second steps of the new route
if (!validFirstStep(firstStep) || !validSecondStep(secondStep, routeProgress)) {
return false;
}
}
}
// New route must be at least 10% faster
if (newRoute.duration() <= (0.9 * currentDurationRemaining)) {
return true;
}
}
return false;
}
use of com.mapbox.api.directions.v5.models.LegStep in project mapbox-navigation-android by mapbox.
the class MetricsRouteProgress method retrieveRouteDestination.
private Point retrieveRouteDestination(DirectionsRoute route) {
RouteLeg lastLeg = route.legs().get(route.legs().size() - 1);
LegStep lastStep = lastLeg.steps().get(lastLeg.steps().size() - 1);
StepManeuver finalManuever = lastStep.maneuver();
if (finalManuever.location() != null) {
return finalManuever.location();
}
return Point.fromLngLat(0d, 0d);
}
use of com.mapbox.api.directions.v5.models.LegStep in project mapbox-navigation-android by mapbox.
the class RouteLegProgress method create.
/**
* Constructor for the route leg progress information.
*
* @param routeLeg the current {@link RouteLeg} the user is traversing along
* @param stepIndex the current step index the user is on
* @param legDistanceRemaining the leg distance remaining which is calculated in navigation engine
* @param stepDistanceRemaining the step distance remaining which is calculated in navigation engine
* @since 0.1.0
*/
static RouteLegProgress create(RouteLeg routeLeg, int stepIndex, double legDistanceRemaining, double stepDistanceRemaining) {
LegStep nextStep = stepIndex == (routeLeg.steps().size() - 1) ? null : routeLeg.steps().get(stepIndex + 1);
RouteStepProgress stepProgress = RouteStepProgress.create(routeLeg.steps().get(stepIndex), nextStep, stepDistanceRemaining);
return new AutoValue_RouteLegProgress(routeLeg, stepIndex, legDistanceRemaining, stepProgress);
}
Aggregations