requireMapboxNavigation
fun LifecycleOwner.requireMapboxNavigation( onCreatedObserver: MapboxNavigationObserver? = null, onStartedObserver: MapboxNavigationObserver? = null, onResumedObserver: MapboxNavigationObserver? = null, onInitialize: () -> Unit? = null): ReadOnlyProperty<Any, MapboxNavigation>
Content copied to clipboard
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()
Content copied to clipboard
Initialize the MapboxNavigationApp when you are ready to use it
val mapboxNavigation by requireMapboxNavigation {
MapboxNavigationApp.setup(..)
}
Content copied to clipboard
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()
)
}
Content copied to clipboard
See also
for more details.