メインコンテンツまでスキップ

Navigation events

Navigation SDK UX Framework exposes the set of the NavigationEvents to observe transitions between navigation states.

There are Navigation Events which can be observed from UX Framework:

  • OnFreeDrive. The event is fired when the navigation system switches to the FreeDrive state or when it is in the FreeDrive state during the subscription.
  • OnNavigationStart. The event is fired when navigation starts.
  • OnNavigationCancel. The event is fired when navigation is canceled from any state except final destination Arrival.
  • OnNavigationEnd. The event is fired when navigation has ended after arriving at the final destination.
  • OnOffRoute. The event is fired when navigation system detects off-route.
  • OnWaypointArrival. The event is fired when navigation arrives at an intermediate waypoint..
  • OnWaypointPass. The event is fired when an intermediate waypoint is passed, and navigation continues to the next waypoint.
  • OnDestinationArrival. The event is fired when navigation arrives at the final destination..

The host application can observe the Navigation Event changes through the Dash.controller instance.

class MainActivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)

lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
Dash.controller.observeNavigationEvents()
.collect { /* NavigationEvent */ event ->
// Do something with the NavigationEvent
processNavigationEvents(event)
}
}
}
}

fun processNavigationEvents(event: NavigationEvent) {
val message = when (event) {
is NavigationEvent.OnFreeDrive -> "App switched to the FreeDrive mode"
is NavigationEvent.OnNavigationStart -> "Navigation was started"
is NavigationEvent.OnNavigationCancel -> "Navigation was cancelled before the arrival to the destination point"
is NavigationEvent.OnNavigationEnd -> "Navigation was ended because of the arrival to the destination point"
is NavigationEvent.OnOffRoute -> "You are off-route"
is NavigationEvent.OnWaypointArrival -> "You have arrived to the intermediate waypoint"
is NavigationEvent.OnWaypointPass -> "Moving to the next waypoint"
is NavigationEvent.OnDestinationArrival -> "Arriving to the final destination"
}

Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
}
}
この{Type}は役に立ちましたか?