use of com.mapbox.api.directions.v5.models.StepManeuver in project mapbox-navigation-android by mapbox.
the class NavigationHelper method checkBearingForStepCompletion.
/**
* Checks whether the user's bearing matches the next step's maneuver provided bearingAfter
* variable. This is one of the criteria's required for the user location to be recognized as
* being on the next step or potentially arriving.
* <p>
* If the expected turn angle is less than the max turn completion offset, this method will
* wait for the step distance remaining to be 0. This way, the step index does not increase
* prematurely.
*
* @param userLocation the location of the user
* @param previousRouteProgress used for getting the most recent route information
* @return boolean true if the user location matches (using a tolerance) the final heading
* @since 0.2.0
*/
static boolean checkBearingForStepCompletion(Location userLocation, RouteProgress previousRouteProgress, double stepDistanceRemaining, double maxTurnCompletionOffset) {
if (previousRouteProgress.currentLegProgress().upComingStep() == null) {
return false;
}
// Bearings need to be normalized so when the bearingAfter is 359 and the user heading is 1, we
// count this as within the MAXIMUM_ALLOWED_DEGREE_OFFSET_FOR_TURN_COMPLETION.
StepManeuver maneuver = previousRouteProgress.currentLegProgress().upComingStep().maneuver();
double initialBearing = maneuver.bearingBefore();
double initialBearingNormalized = MathUtils.wrap(initialBearing, 0, 360);
double finalBearing = maneuver.bearingAfter();
double finalBearingNormalized = MathUtils.wrap(finalBearing, 0, 360);
double expectedTurnAngle = MathUtils.differenceBetweenAngles(initialBearingNormalized, finalBearingNormalized);
double userBearingNormalized = MathUtils.wrap(userLocation.getBearing(), 0, 360);
double userAngleFromFinalBearing = MathUtils.differenceBetweenAngles(finalBearingNormalized, userBearingNormalized);
if (expectedTurnAngle <= maxTurnCompletionOffset) {
return stepDistanceRemaining == 0;
} else {
return userAngleFromFinalBearing <= maxTurnCompletionOffset;
}
}
use of com.mapbox.api.directions.v5.models.StepManeuver in project mapbox-navigation-android by mapbox.
the class MetricsRouteProgress method obtainStepData.
private void obtainStepData(RouteProgress routeProgress) {
RouteLegProgress legProgress = routeProgress.currentLegProgress();
if (legProgress.upComingStep() != null) {
upcomingStepName = legProgress.upComingStep().name();
StepManeuver upcomingManeuver = legProgress.upComingStep().maneuver();
if (upcomingManeuver != null) {
upcomingStepInstruction = upcomingManeuver.instruction();
upcomingStepType = upcomingManeuver.type();
upcomingStepModifier = upcomingManeuver.modifier();
}
}
StepManeuver currentManeuver = legProgress.currentStep().maneuver();
if (currentManeuver != null) {
previousStepInstruction = currentManeuver.instruction();
previousStepType = currentManeuver.type();
previousStepModifier = currentManeuver.modifier();
}
previousStepName = currentStepName;
}
use of com.mapbox.api.directions.v5.models.StepManeuver 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);
}
Aggregations