MapboxNavigation

class MapboxNavigation

Mapbox Navigation Core SDK

An entry point for interacting with the Mapbox Navigation SDK.

Only one instance of this class should be used per application process. Use MapboxNavigationProvider to easily manage the instance across lifecycle.

Feel free to visit our docs pages and examples before diving in!

The MapboxNavigation implementation can enter into the following NavigationSessionStates:

The SDK starts off in an Idle state.

Location

Whenever the startTripSession is called, the SDK will enter the FreeDrive state starting to request and propagate location updates via the LocationObserver.

This observer provides 2 location update values in mixed intervals - either the raw one received from the provided LocationEngine or the enhanced one map-matched internally using SDK's native capabilities.

In FreeDrive mode, the enhanced location is computed using nearby to user location's routing tiles that are continuously updating in the background. This can be configured using the RoutingTilesOptions in the NavigationOptions.

If the session is stopped, the SDK will stop listening for raw location updates and enter the Idle state.

Routing

A route can be requested with:

  • requestRoutes, if successful, returns a route reference without acting on it. You can then pass the generated routes to setRoutes.

  • setRoutes sets new routes, clear current ones, or changes the route at primary index 0. The routes are immediately available via the RoutesObserver and the first route (at index 0) is going to be chosen as the primary one.

Route reason update

When routes are updated via setRoutes the reason that is spread via RoutesObserver.onRoutesChanged might be:

Make sure to use the applyDefaultNavigationOptions for the best navigation experience (and to set required request parameters). You can also use applyLanguageAndVoiceUnitOptions get instructions' language and voice unit based on the device's Locale. It's also worth exploring other available options (like enabling alternative routes, specifying destination approach type, defining waypoint types, etc.).

Example:

val routeOptions = RouteOptions.builder()
.applyDefaultNavigationOptions()
.applyLanguageAndVoiceUnitOptions(context)
.accessToken(token)
.coordinatesList(listOf(origin, destination))
.alternatives(true)
.build()
mapboxNavigation.requestRoutes(
routeOptions,
object : RouterCallback {
override fun onRoutesReady(routes: List<DirectionsRoute>) {
mapboxNavigation.setRoutes(routes)
}
override fun onFailure(reasons: List<RouterFailure>, routeOptions: RouteOptions) { }
override fun onCanceled(routeOptions: RouteOptions) { }
}
)

If the SDK is in an Idle state, it stays in this same state even when a primary route is available.

If the SDK is already in the FreeDrive mode or entering it whenever a primary route is available, the SDK will enter the ActiveGuidance mode instead and propagate meaningful RouteProgress.

When the routes are manually cleared, the SDK automatically fall back to either Idle or FreeDrive state.

You can use setRoutes to provide new routes, clear current ones, or change the route at primary index 0.

Parameters

navigationOptions

a set of NavigationOptions used to customize various features of the SDK.

Constructors

MapboxNavigation
Link copied to clipboard
fun MapboxNavigation(navigationOptions: NavigationOptions)

Functions

cancelRouteRequest
Link copied to clipboard
fun cancelRouteRequest(requestId: Long)
Cancels a specific route request using the ID returned by requestRoutes.
equals
Link copied to clipboard
open operator fun equals(other: Any?): Boolean
getNavigationSessionState
Link copied to clipboard
fun getNavigationSessionState(): NavigationSessionState
Provides the current navigation session state.
getRerouteController
Link copied to clipboard
fun getRerouteController(): RerouteController?
Get currently set RerouteController.
getRoutes
Link copied to clipboard
fun getRoutes(): List<DirectionsRoute>
Get a list of routes.
getTripSessionState
Link copied to clipboard
fun getTripSessionState(): TripSessionState
Return the current TripSession's state.
getZLevel
Link copied to clipboard
fun getZLevel(): Int?
Provides the current Z-Level.
hashCode
Link copied to clipboard
open fun hashCode(): Int
isRunningForegroundService
Link copied to clipboard
fun isRunningForegroundService(): Boolean
Query if the MapboxNavigation is running a foreground service
navigateNextRouteLeg
Link copied to clipboard
fun navigateNextRouteLeg(callback: LegIndexUpdatedCallback)
After arriving at a stop, this can be used to manually decide when to start navigating to the next stop.
onDestroy
Link copied to clipboard
fun onDestroy()
Call this method whenever this instance of the MapboxNavigation is not going to be used anymore and should release all of its resources.
postUserFeedback
Link copied to clipboard
fun postUserFeedback(feedbackType: String, description: String, feedbackSource: String, screenshot: String, feedbackSubType: Array<String>? = emptyArray())
Send user feedback about an issue or problem with the Navigation SDK.
fun postUserFeedback(feedbackType: String, description: String, feedbackSource: String, screenshot: String, feedbackSubType: Array<String>? = emptyArray(), feedbackMetadata: FeedbackMetadata)
Send user feedback about an issue or problem with the Navigation SDK.
provideFeedbackMetadataWrapper
Link copied to clipboard
Provides wrapper of FeedbackMetadata.
registerArrivalObserver
Link copied to clipboard
fun registerArrivalObserver(arrivalObserver: ArrivalObserver)
Registers ArrivalObserver.
registerBannerInstructionsObserver
Link copied to clipboard
fun registerBannerInstructionsObserver(bannerInstructionsObserver: BannerInstructionsObserver)
registerEHorizonObserver
Link copied to clipboard
fun registerEHorizonObserver(eHorizonObserver: EHorizonObserver)
To start listening EHorizon updates EHorizonObserver should be registered.
registerLocationObserver
Link copied to clipboard
fun registerLocationObserver(locationObserver: LocationObserver)
Registers LocationObserver.
registerNavigationSessionStateObserver
Link copied to clipboard
fun registerNavigationSessionStateObserver(navigationSessionStateObserver: NavigationSessionStateObserver)
Register a NavigationSessionStateObserver to be notified of the various Session states.
registerNavigationVersionSwitchObserver
Link copied to clipboard
Start observing navigation tiles version switch via NavigationVersionSwitchObserver.
registerOffRouteObserver
Link copied to clipboard
fun registerOffRouteObserver(offRouteObserver: OffRouteObserver)
Registers OffRouteObserver.
registerRoadObjectsOnRouteObserver
Link copied to clipboard
fun registerRoadObjectsOnRouteObserver(roadObjectsOnRouteObserver: RoadObjectsOnRouteObserver)
Registers an observer that gets notified whenever the route changes and provides the list of road objects on this new route, if there are any.
registerRouteAlternativesObserver
Link copied to clipboard
fun registerRouteAlternativesObserver(routeAlternativesObserver: RouteAlternativesObserver)
Start observing alternatives routes for a trip session via RouteAlternativesObserver.
registerRouteProgressObserver
Link copied to clipboard
fun registerRouteProgressObserver(routeProgressObserver: RouteProgressObserver)
registerRoutesObserver
Link copied to clipboard
fun registerRoutesObserver(routesObserver: RoutesObserver)
Registers RoutesObserver.
registerTripSessionStateObserver
Link copied to clipboard
fun registerTripSessionStateObserver(tripSessionStateObserver: TripSessionStateObserver)
registerVoiceInstructionsObserver
Link copied to clipboard
fun registerVoiceInstructionsObserver(voiceInstructionsObserver: VoiceInstructionsObserver)
requestAlternativeRoutes
Link copied to clipboard
fun requestAlternativeRoutes(callback: RouteAlternativesRequestCallback? = null)
Requests an alternative route using the original RouteOptions associated with MapboxNavigation.setRoutes() call and Router implementation.
requestRoutes
Link copied to clipboard
fun requestRoutes(routeOptions: RouteOptions, routesRequestCallback: RouterCallback): Long
Requests a route using the available Router implementation.
resetTripSession
Link copied to clipboard
fun resetTripSession()
Reset the session with the same configuration.
setArrivalController
Link copied to clipboard
fun setArrivalController(arrivalController: ArrivalController? = AutoArrivalController())
Set your own controller to determine when drivers arrived at stops via ArrivalController.
setRerouteController
Link copied to clipboard
fun setRerouteController(rerouteController: RerouteController? = defaultRerouteController)
Set RerouteController that's automatically invoked when user is off-route.
setRoutes
Link copied to clipboard
fun setRoutes(routes: List<DirectionsRoute>, initialLegIndex: Int = 0)
Set a list of routes.
startReplayTripSession
Link copied to clipboard
fun startReplayTripSession(withForegroundService: Boolean = true)
Functionally the same as startTripSession except the locations do not come from the NavigationOptions.locationEngine.
startTripSession
Link copied to clipboard
@RequiresPermission(anyOf = ["android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"])
fun startTripSession(withForegroundService: Boolean = true)
Starts listening for location updates and enters an Active Guidance state if there's a primary route available or a Free Drive state otherwise.
stopTripSession
Link copied to clipboard
fun stopTripSession()
Stops listening for location updates and enters an Idle state.
toString
Link copied to clipboard
open fun toString(): String
unregisterArrivalObserver
Link copied to clipboard
fun unregisterArrivalObserver(arrivalObserver: ArrivalObserver)
Unregisters ArrivalObserver.
unregisterBannerInstructionsObserver
Link copied to clipboard
fun unregisterBannerInstructionsObserver(bannerInstructionsObserver: BannerInstructionsObserver)
unregisterEHorizonObserver
Link copied to clipboard
fun unregisterEHorizonObserver(eHorizonObserver: EHorizonObserver)
Unregisters a EHorizon observer.
unregisterLocationObserver
Link copied to clipboard
fun unregisterLocationObserver(locationObserver: LocationObserver)
Unregisters LocationObserver.
fun unregisterNavigationSessionStateObserver(navigationSessionStateObserver: NavigationSessionStateObserver)
Stop observing tiles version switch via NavigationVersionSwitchObserver.
unregisterOffRouteObserver
Link copied to clipboard
fun unregisterOffRouteObserver(offRouteObserver: OffRouteObserver)
Unregisters OffRouteObserver.
unregisterRoadObjectsOnRouteObserver
Link copied to clipboard
fun unregisterRoadObjectsOnRouteObserver(roadObjectsOnRouteObserver: RoadObjectsOnRouteObserver)
Unregisters the route objects observer.
unregisterRouteAlternativesObserver
Link copied to clipboard
fun unregisterRouteAlternativesObserver(routeAlternativesObserver: RouteAlternativesObserver)
Stop observing the possibility of route alternatives.
unregisterRouteProgressObserver
Link copied to clipboard
fun unregisterRouteProgressObserver(routeProgressObserver: RouteProgressObserver)
unregisterRoutesObserver
Link copied to clipboard
fun unregisterRoutesObserver(routesObserver: RoutesObserver)
Unregisters RoutesObserver.
unregisterTripSessionStateObserver
Link copied to clipboard
fun unregisterTripSessionStateObserver(tripSessionStateObserver: TripSessionStateObserver)
unregisterVoiceInstructionsObserver
Link copied to clipboard
fun unregisterVoiceInstructionsObserver(voiceInstructionsObserver: VoiceInstructionsObserver)

Properties

experimental
Link copied to clipboard
val experimental: Experimental
THIS IS AN EXPERIMENTAL API, DO NOT USE IN A PRODUCTION ENVIRONMENT.
graphAccessor
Link copied to clipboard
val graphAccessor: GraphAccessor
MapboxNavigation.graphAccessor provides methods to get edge (e.g.
historyRecorder
Link copied to clipboard
val historyRecorder: MapboxHistoryRecorder
Use the history recorder to save history files.
isDestroyed
Link copied to clipboard
var isDestroyed: Boolean = false
Describes whether this instance of MapboxNavigation has been destroyed by calling onDestroy.
mapboxReplayer
Link copied to clipboard
val mapboxReplayer: MapboxReplayer
Control the location events playback during a replay trip session.
navigationOptions
Link copied to clipboard
val navigationOptions: NavigationOptions
a set of NavigationOptions used to customize various features of the SDK.
roadObjectMatcher
Link copied to clipboard
val roadObjectMatcher: RoadObjectMatcher
MapboxNavigation.roadObjectMatcher provides methods to match custom road objects to the road graph.
roadObjectsStore
Link copied to clipboard
val roadObjectsStore: RoadObjectsStore
MapboxNavigation.roadObjectsStore provides methods to get road objects metadata, add and remove custom road objects.
tilesetDescriptorFactory
Link copied to clipboard
val tilesetDescriptorFactory: TilesetDescriptorFactory
MapboxNavigation.tilesetDescriptorFactory provide methods to build navigation TilesetDescriptor