MapboxNavigation

class MapboxNavigation(navigationOptions: NavigationOptions)

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 a couple of internal states:

  • Idle

  • Free Drive

  • Active Guidance

The SDK starts off in an Idle state.

Location

Whenever the startTripSession is called, the SDK will enter the Free Drive 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 Free Drive 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 OnboardRouterOptions 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 the request is successful and returns a non-empty list of routes in the RoutesObserver, the first route at index 0 is going to be chosen as a primary one.

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 Free Drive mode or entering it whenever a primary route is available, the SDK will enter the Active Guidance mode instead and propagate meaningful RouteProgress.

If a new routes request is made, or the routes are manually cleared, the SDK automatically fall back to either Idle or Free Drive 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. Use defaultNavigationOptionsBuilder to set default options

Constructors

MapboxNavigation
Link copied to clipboard
fun MapboxNavigation(navigationOptions: NavigationOptions)
a set of NavigationOptions used to customize various features of the SDK.

Types

Companion
Link copied to clipboard
object Companion

Functions

addHistoryEvent
Link copied to clipboard
fun addHistoryEvent(eventType: String, eventJsonProperties: String)
API used to artificially add debug events to logs.
attachFasterRouteObserver
Link copied to clipboard
fun attachFasterRouteObserver(fasterRouteObserver: FasterRouteObserver)
Start observing faster routes for a trip session via FasterRouteObserver
detachFasterRouteObserver
Link copied to clipboard
fun detachFasterRouteObserver()
Stop observing the possibility of faster routes.
equals
Link copied to clipboard
open operator fun equals(other: Any?): Boolean
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.
hashCode
Link copied to clipboard
open fun hashCode(): Int
navigateNextRouteLeg
Link copied to clipboard
fun navigateNextRouteLeg(): Boolean
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(), appMetadata: AppMetadata? = null)
Send user feedback about an issue or problem with the Navigation SDK.
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)
Observer will be called when the EHorizon changes.
registerLocationObserver
Link copied to clipboard
fun registerLocationObserver(locationObserver: LocationObserver)
Registers LocationObserver.
registerMapMatcherResultObserver
Link copied to clipboard
fun registerMapMatcherResultObserver(mapMatcherResultObserver: MapMatcherResultObserver)
Registers an observer that gets notified whenever a new enhanced location update is available with details about the status of the enhanced location.
registerOffRouteObserver
Link copied to clipboard
fun registerOffRouteObserver(offRouteObserver: OffRouteObserver)
Registers OffRouteObserver.
registerRouteAlertsObserver
Link copied to clipboard
fun registerRouteAlertsObserver(routeAlertsObserver: RouteAlertsObserver)
Registers an observer that gets notified whenever the route changes and provides the list of alerts on this new route, if there are any.
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)
requestRoutes
Link copied to clipboard
fun requestRoutes(routeOptions: RouteOptions, routesRequestCallback: RoutesRequestCallback? = null)
Requests a route using the provided Router implementation.
resetTripSession
Link copied to clipboard
fun resetTripSession()
Reset the session with the same configuration.
retrieveHistory
Link copied to clipboard
fun retrieveHistory(): String
API used to retrieve logged location and route progress samples for debug purposes.
retrieveSsmlAnnouncementInstruction
Link copied to clipboard
fun retrieveSsmlAnnouncementInstruction(index: Int): String?
API used to retrieve the SSML announcement for voice instructions.
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>)
Set a list of routes.
startTripSession
Link copied to clipboard
@RequiresPermission(anyOf = ["android.permission.ACCESS_COARSE_LOCATION", "android.permission.ACCESS_FINE_LOCATION"])
fun startTripSession()
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.
toggleHistory
Link copied to clipboard
fun toggleHistory(isEnabled: Boolean)
API used to enable/disable location and route progress samples logs for debug purposes.
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.
unregisterMapMatcherResultObserver
Link copied to clipboard
fun unregisterMapMatcherResultObserver(mapMatcherResultObserver: MapMatcherResultObserver)
unregisterOffRouteObserver
Link copied to clipboard
fun unregisterOffRouteObserver(offRouteObserver: OffRouteObserver)
Unregisters OffRouteObserver.
unregisterRouteAlertsObserver
Link copied to clipboard
fun unregisterRouteAlertsObserver(routeAlertsObserver: RouteAlertsObserver)
Unregisters the route alerts observer.
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)
updateSensorEvent
Link copied to clipboard
fun updateSensorEvent(sensorEvent: SensorEvent)
Sends an event to improve navigation positioning.

Properties

navigationOptions
Link copied to clipboard
val navigationOptions: NavigationOptions
a set of NavigationOptions used to customize various features of the SDK.