NavigationHelper

This contains several single purpose methods that help out when a new location update occurs and calculations need to be performed on it.

Functions

Link copied to clipboard
fun buildSnappedLocation(mapLibreNavigation: MapLibreNavigation, snapToRouteEnabled: Boolean, rawLocation: Location, routeProgress: RouteProgress, userOffRoute: Boolean): Location
Link copied to clipboard
fun checkBearingForStepCompletion(userLocation: Location, previousRouteProgress: RouteProgress, stepDistanceRemaining: Double, maxTurnCompletionOffset: Double): Boolean

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.

Link copied to clipboard
fun checkMilestones(previousRouteProgress: RouteProgress?, routeProgress: RouteProgress, mapLibreNavigation: MapLibreNavigation): List<Milestone>

This method runs through the list of milestones in MapLibreNavigation.milestones and returns a list of occurring milestones (if any), based on their individual criteria.

Link copied to clipboard
fun createCurrentAnnotation(currentLegAnnotation: CurrentLegAnnotation?, leg: RouteLeg, legDistanceRemaining: Double): CurrentLegAnnotation?

Given a list of distance annotations, find the current annotation index. This index retrieves the current annotation from any provided annotation list in LegAnnotation.

Link copied to clipboard

Creates a list of pairs StepIntersection and double distance in meters along a step.

Link copied to clipboard

Given a current and upcoming step, this method assembles a list of StepIntersection consisting of all of the current step intersections, as well as the first intersection of the upcoming step (if the upcoming step isn't null).

Link copied to clipboard
fun decodeStepPoints(directionsRoute: DirectionsRoute, currentPoints: List<Point>, legIndex: Int, stepIndex: Int): List<Point>

Given the current DirectionsRoute and leg / step index, return a list of Point representing the current step.

Link copied to clipboard
fun findCurrentIntersection(intersections: List<StepIntersection>, measuredIntersections: List<Pair<StepIntersection?, Double>>, stepDistanceTraveled: Double): StepIntersection?

fun findCurrentIntersection(intersections: List<StepIntersection>, measuredIntersections: Map<StepIntersection, Double>, stepDistanceTraveled: Double): StepIntersection?

Based on the list of measured intersections and the step distance traveled, finds the current intersection a user is traveling along.

Link copied to clipboard
fun findUpcomingIntersection(intersections: List<StepIntersection>, upcomingStep: LegStep?, currentIntersection: StepIntersection): StepIntersection?

Based on the current intersection index, add one and try to get the upcoming.

Link copied to clipboard

This is used when a user has completed a step maneuver and the indices need to be incremented. The main purpose of this class is to determine if an additional leg exist and the step index has met the first legs total size, a leg index needs to occur and step index should be reset. Otherwise, the step index is incremented while the leg index remains the same.

Link copied to clipboard
fun isUserOffRoute(mapLibreNavigation: MapLibreNavigation, location: Location, routeProgress: RouteProgress, callback: OffRouteCallback): Boolean

This method checks if off route detection is enabled or disabled.

Link copied to clipboard
fun legDistanceRemaining(stepDistanceRemaining: Double, legIndex: Int, stepIndex: Int, directionsRoute: DirectionsRoute): Double

Takes in the already calculated step distance and iterates through the step list from the step index value plus one till the end of the leg.

Link copied to clipboard
fun nextManeuverPosition(stepIndex: Int, steps: List<LegStep>, coords: List<Point?>): Point?

Retrieves the next steps maneuver position if one exist, otherwise it decodes the current steps geometry and uses the last coordinate in the position list.

Link copied to clipboard
fun routeDistanceRemaining(legDistanceRemaining: Double, legIndex: Int, directionsRoute: DirectionsRoute): Double

Takes in the leg distance remaining value already calculated and if additional legs need to be traversed along after the current one, adds those distances and returns the new distance. Otherwise, if the route only contains one leg or the users on the last leg, this value will equal the leg distance remaining.

Link copied to clipboard
fun shouldCheckFasterRoute(navigationLocationUpdate: NavigationLocationUpdate, routeProgress: RouteProgress): Boolean
Link copied to clipboard
fun stepDistanceRemaining(location: Location, legIndex: Int, stepIndex: Int, directionsRoute: DirectionsRoute, stepPoints: List<Point>): Double

Calculates the distance remaining in the step from the current users snapped position, to the next maneuver position.