navigationState

abstract val navigationState: StateFlow<NavigationState>

A StateFlow representing the current state of the navigation session

Collect this flow to observe state changes.

Custom implementation of StateFlow guarantees all changes to be notify - no conflation.

Example:

...
val params = NavigationParams.Builder(Waypoint(latitude, longitude))
.setStartForegroundService(startForegroundService)
.build()
NavigationApi.navigate(latitude, longitude)
...
lifecycleScope.launch {
NavigationApi.navigationState.collect { state ->
when(state) {
is NavigationState.NotStarted -> { /* Navigation not started yet - new one can be started */}
is NavigationState.Starting -> { /* Navigation is starting - check errors if any problem occurred */}
is NavigationState.Navigating -> { /* Ongoing navigation - get more data from this state if needed */}
is NavigationState.Stopping -> { /* Navigation is stopping */}
}
}
}

See also