Navigation SDK for Android
Beta

Maneuver instructions

The Mapbox Navigation SDK allows you to provide voice and text instructions to your users at defined locations along a user's route.

Voice instructions

The Navigation SDK uses the Mapbox Java SDK's VoiceInstructions class to hold information that should be announced out loud by the device (for example, the street that the user should stay on for a certain distance).

Request voice instructions

To include voice instructions in your route request response, your directions route request must pass true through the RouteOptions.builder()'s voiceInstructions() method. Read more about the Directions API's voice instructions information.

Listen to voice instructions

The VoiceInstructionsObserver observer interface provides a VoiceInstructions object whenever it's time to announce instructions as the user moves along a DirectionsRoute. To listen to voice instructions:

  1. Create the interface object:
val voiceInstructionsObserver = object : VoiceInstructionsObserver {
    override fun onNewVoiceInstructions(voiceInstructions: VoiceInstructions) {
        
    }
}
  1. Register the interface object with your already-instantiated MapboxNavigation object:
mapboxNavigation.registerVoiceInstructionsObserver(voiceInstructionsObserver)
  1. Don’t forget to unregister the VoiceInstructionsObserver interface!:
override fun onStop() {
  super.onStop()    
  mapView.onStop()

  mapboxNavigation.unregisterVoiceInstructionsObserver(voiceInstructionsObserver)
}

The Navigation SDK uses the Mapbox Java SDK's BannerInstructions class to hold information about the next step along a directions route. The Navigation SDK uses this information to display instructions on the device's screen (for example, the name of the street a user should turn left on to and the remaining distance until that turn left maneuver).

Request banner instructions

To include banner text instructions in your route request response, your directions route request must pass true through the RouteOptions.builder()'s bannerInstructions() method. This will instruct the Navigation SDK to make the correct call to the Directions API. See the Directions API documentation for more information on route step and step maneuver.

Listen to banner instructions

The BannerInstructionsObserver observer interface provides a BannerInstructions object whenever it's time to display instructions as the user moves along a DirectionsRoute. To listen to banner instructions:

  1. Create the BannerInstructionsObserver observer:
val bannerInstructionsObserver = object: BannerInstructionsObserver{
  override fun willDisplay(bannerInstructions: BannerInstructions) {
  
  }
}
  1. Register the BannerInstructionsObserver with the Navigation SDK's MapboxNavigation class:
mapboxNavigation.registerBannerInstructionsObserver(bannerInstructionsObserver) 
  1. Don’t forget to unregister the BannerInstructionsObserver interface:
override fun onStop() {
  super.onStop()
  mapView.onStop()
    
  mapboxNavigation.unregisterBannerInstructionsObserver(bannerInstructionsObserver)
}
Was this page helpful?