MapLibreNavigation

open class MapLibreNavigation @JvmOverloads constructor(val options: MapLibreNavigationOptions = MapLibreNavigationOptions(), locationEngine: LocationEngine, var cameraEngine: Camera = SimpleCamera(), var snapEngine: Snap = SnapToRoute(), var offRouteEngine: OffRoute = OffRouteDetector(), var fasterRouteEngine: FasterRoute = FasterRouteDetector(options), val routeUtils: RouteUtils = RouteUtils())

A MapLibreNavigation class for interacting with and customizing a navigation session.

Instance of this class are used to setup, customize, start, and end a navigation session. Building a custom MapLibreNavigationOptions object and passing it in allows you to further customize the user experience. Once this class is initialized, the options specified through the options class cannot be modified.

Parameters

applicationContext

required in order to create and bind the navigation service. An application context is required here.

options

a custom built MapLibreNavigationOptions class

locationEngine

a LocationEngine to provide Location updates

cameraEngine

Navigation uses a camera engine to determine the camera position while routing. By default, it uses a SimpleCamera. If you would like to customize how the camera is positioned, create a new Camera and set it here.

snapEngine

This parameter is used to pass in a custom implementation of the snapping logic. A default snap-to-route engine is attached when this class is first initialized; setting a custom one will replace it with your own implementation.

offRouteEngine

This param is used to pass in a custom implementation of the off-route logic, A default off-route detection engine is attached when this class is first initialized; setting a custom one will replace it with your own implementation.

fasterRouteEngine

This API is used to pass in a custom implementation of the faster-route detection logic, A default faster-route detection engine is attached when this class is first initialized; setting a custom one will replace it with your own implementation.

routeUtils

core utility class for route related calculations

See also

Inheritors

AndroidMapLibreNavigation
IOSMapLibreNavigation

Constructors

Link copied to clipboard
constructor(options: MapLibreNavigationOptions = MapLibreNavigationOptions(), locationEngine: LocationEngine, cameraEngine: Camera = SimpleCamera(), snapEngine: Snap = SnapToRoute(), offRouteEngine: OffRoute = OffRouteDetector(), fasterRouteEngine: FasterRoute = FasterRouteDetector(options), routeUtils: RouteUtils = RouteUtils())

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Navigation needs an instance of location engine in order to acquire user location information and handle events based off of the current information. By default, a LOST location engine is created with the optimal navigation settings.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard

This adds a new faster route listener which is invoked when a new, faster DirectionsRoute has been retrieved by the specified criteria in FasterRoute.

Link copied to clipboard
fun addMilestone(milestone: Milestone)

Navigation Milestones provide a powerful way to give your user instructions at custom defined locations along their route. Default milestones are automatically added unless MapLibreNavigationOptions.defaultMilestonesEnabled is set to false but they can also be individually removed using the .removeMilestone API. Once a custom milestone is built, it will need to be passed into the navigation SDK through this method.

Link copied to clipboard

This adds a new milestone event listener which is invoked when a milestone gets triggered. If more then one milestone gets triggered on a location update, each milestone event listener will be invoked for each of those milestones. This is important to consider if you are using voice instructions since this would cause multiple instructions to be said at once. Ideally the milestones setup should avoid triggering too close to each other.

Link copied to clipboard
fun addMilestones(milestones: List<Milestone>)

Adds the given list of Milestone to be triggered during navigation.

Link copied to clipboard

This adds a new navigation event listener which is invoked when navigation service begins running in the background and again when the service gets destroyed.

Link copied to clipboard
fun addOffRouteListener(offRouteListener: OffRouteListener)

This adds a new off route listener which is invoked when the devices location veers off the route and the specified criteria's in MapLibreNavigationOptions have been met.

Link copied to clipboard

This adds a new progress change listener which is invoked when a location change occurs and the navigation engine successfully runs it's calculations on it.

Link copied to clipboard
fun onDestroy()

Critical to place inside your navigation activity so that when your application gets destroyed the navigation service unbinds and gets destroyed, preventing any memory leaks. Calling this also removes all listeners that have been attached.

Link copied to clipboard

This removes a specific faster route listener by passing in the instance of it or you can pass in null to remove all the listeners. When .onDestroy is called, all listeners get removed automatically, removing the requirement for developers to manually handle this.

Link copied to clipboard
fun removeMilestone(milestoneIdentifier: Int)

Remove a specific milestone by passing in the identifier associated with the milestone you'd like to remove. If the identifier passed in does not match one of the milestones in the list, a warning will return in the log.

fun removeMilestone(milestone: Milestone?)

Remove a specific milestone by passing in the instance of it. Removal of all the milestones can be achieved by passing in null rather than a specific milestone.

Link copied to clipboard

This removes a specific milestone event listener by passing in the instance of it or you can pass in null to remove all the listeners. When .onDestroy is called, all listeners get removed automatically, removing the requirement for developers to manually handle this.

Link copied to clipboard

This removes a specific navigation event listener by passing in the instance of it or you can pass in null to remove all the listeners. When .onDestroy is called, all listeners get removed automatically, removing the requirement for developers to manually handle this.

Link copied to clipboard

This removes a specific off route listener by passing in the instance of it or you can pass in null to remove all the listeners. When .onDestroy is called, all listeners get removed automatically, removing the requirement for developers to manually handle this.

Link copied to clipboard

This removes a specific progress change listener by passing in the instance of it or you can pass in null to remove all the listeners. When .onDestroy is called, all listeners get removed automatically, removing the requirement for developers to manually handle this.

Link copied to clipboard
fun startNavigation(directionsRoute: DirectionsRoute)

Calling This begins a new navigation session using the provided directions route. this API is also intended to be used when a reroute occurs passing in the updated directions route.

Link copied to clipboard

Call this when the navigation session needs to end before the user reaches their final destination. There isn't a need to manually end the navigation session using this API when the user arrives unless you set MapLibreNavigationOptions.manuallyEndNavigationUponCompletion to true.