requireMapboxNavigation

fun LifecycleOwner.requireMapboxNavigation(onCreatedObserver: MapboxNavigationObserver? = null, onStartedObserver: MapboxNavigationObserver? = null, onResumedObserver: MapboxNavigationObserver? = null, onInitialize: () -> Unit? = null): ReadOnlyProperty<Any, MapboxNavigation>

Extension function to make it simple to create the RequireMapboxNavigationDelegate. Below are a couple examples of how you may use the delegate.

Default can be used when MapboxNavigationApp is setup elsewhere.

val mapboxNavigation by requireMapboxNavigation()

Initialize the MapboxNavigationApp when you are ready to use it

val mapboxNavigation by requireMapboxNavigation {
MapboxNavigationApp.setup(..)
}

Register subscriptions and setup MapboxNavigationApp

private val mapboxNavigation by requireMapboxNavigation(
onResumedObserver = object : MapboxNavigationObserver {
override fun onAttached(mapboxNavigation: MapboxNavigation) {
mapboxNavigation.registerLocationObserver(locationObserver)
mapboxNavigation.registerRoutesObserver(routesObserver)
}
override fun onDetached(mapboxNavigation: MapboxNavigation) {
mapboxNavigation.unregisterLocationObserver(locationObserver)
mapboxNavigation.unregisterRoutesObserver(routesObserver)
}
}
) {
MapboxNavigationApp.setup(
NavigationOptions.Builder(this)
.accessToken(accessToken)
.build()
)
}

See also