Automotive Navigation Application

Driving with a route

Request access

Driving with a route

The GuidanceManager provides navigation guidance during active trips. It delivers turn-by-turn instructions and lane guidance to help drivers navigate their routes.

Starting navigation

Before observing guidance information, start navigation on a planned trip:

import android.util.Log
import com.tomtom.automotive.integration.client.api.trip.TripManager
import com.tomtom.automotive.integration.client.api.trip.startnavigation.StartNavigationCallback
import com.tomtom.automotive.integration.client.api.trip.startnavigation.StartNavigationFailure
import com.tomtom.automotive.integration.client.api.trip.startnavigation.StartNavigationParameters
import com.tomtom.automotive.integration.client.api.trip.startnavigation.StartNavigationResponse
import com.tomtom.automotive.integration.client.common.Callback
import com.tomtom.automotive.integration.client.common.Result
import com.tomtom.automotive.integration.client.common.SdkReleasable
private const val TAG = "Navigation"
fun startNavigation(tripManager: TripManager, tripId: String) {
tripManager.startNavigation(
StartNavigationParameters(tripId),
object : StartNavigationCallback {
override fun onNavigatedTrip(response: Result<StartNavigationResponse, StartNavigationFailure>) {
when (response) {
is Result.Success -> {
val trip = response.value.navigatedTrip
Log.d(TAG, "Navigation started for trip: ${trip.id}")
}
is Result.Failure -> {
Log.e(TAG, "Failed to start navigation: ${response.failure}")
}
}
}
override fun onFunctionalityUnavailable(reason: Callback.Reason) {
Log.e(TAG, "Navigation unavailable: ${reason.devMessage}")
}
}
)
}

Observing next instruction

Subscribe to receive updates about the next maneuver:

import android.util.Log
import com.tomtom.automotive.integration.client.api.guidance.GuidanceManager
import com.tomtom.automotive.integration.client.api.guidance.observenextinstruction.InstructionInfo
import com.tomtom.automotive.integration.client.api.guidance.observenextinstruction.NextInstructionListener
import com.tomtom.automotive.integration.client.api.model.guidance.InstructionInformation
import com.tomtom.automotive.integration.client.common.Callback
import com.tomtom.automotive.integration.client.common.SdkReleasable
private const val TAG = "Guidance"
private var observeNextInstructionReleasable: SdkReleasable? = null
fun observeNextInstruction(guidanceManager: GuidanceManager) {
observeNextInstructionReleasable = guidanceManager.observeNextInstruction(
object : NextInstructionListener {
override fun onNextInstructionChange(instructionInfo: InstructionInfo) {
val instruction = instructionInfo.instruction
if (instruction != null) {
val distance = instruction.distanceToNextInstruction
val info = instruction.instruction
Log.d(TAG, "Next instruction in ${distance.meters}m: ${getInstructionDescription(info)}")
// Get road shields if available
info.getRoadShields()?.forEach { shield ->
Log.d(TAG, "Road shield: ${shield.roadNumber}")
}
}
}
override fun onFunctionalityUnavailable(reason: Callback.Reason) {
Log.e(TAG, "Instruction updates unavailable: ${reason.devMessage}")
}
}
)
}
private fun getInstructionDescription(info: InstructionInformation): String {
return when (info) {
is InstructionInformation.TurnInstruction -> "Turn ${info.direction}"
is InstructionInformation.ForkInstruction -> "Fork ${info.direction}"
is InstructionInformation.RoundaboutInstruction -> "Roundabout exit ${info.roundabout.exitNumber}"
is InstructionInformation.ExitHighwayInstruction -> "Exit highway ${info.direction}"
is InstructionInformation.DestinationArrivalInstruction -> "Arrive at destination"
else -> info.toString()
}
}
fun unObserveNextInstruction() {
observeNextInstructionReleasable?.release()
observeNextInstructionReleasable = null
}

Instruction types

The InstructionInformation sealed interface has the following implementations:

  • TurnInstruction - Turn at a road junction
  • RoundaboutInstruction - Enter and navigate a roundabout
  • ExitRoundaboutInstruction - Exit a roundabout
  • ForkInstruction - Fork in a bifurcation
  • FollowRoadInstruction - Continue following the current road
  • MergeInstruction - Merge onto highway/expressway
  • ExitHighwayInstruction - Take a highway exit
  • SwitchHighwayInstruction - Switch highways via exit ramp
  • TollgateInstruction - Approaching toll booth or ETC terminal
  • DestinationArrivalInstruction - Arrival at destination
  • WaypointArrivalInstruction - Arrival at waypoint
  • DepartureInstruction - Starting point of trip
  • BorderCrossingInstruction - Crossing international border
  • EntryAutoTransportInstruction - Enter vehicle transport (ferry, car train)
  • ExitAutoTransportInstruction - Exit vehicle transport
  • EnterCarpoolLaneInstruction - Enter carpool/HOV lane
  • ExitCarpoolLaneInstruction - Exit carpool/HOV lane

Fetching road shield assets

Road shields can be displayed as drawable resources:

import android.util.Log
import com.tomtom.automotive.integration.client.api.asset.AssetManager
import com.tomtom.automotive.integration.client.api.asset.getdrawable.GetDrawableCallback
import com.tomtom.automotive.integration.client.api.asset.getdrawable.GetDrawableFailure
import com.tomtom.automotive.integration.client.api.asset.getdrawable.GetDrawableParameters
import com.tomtom.automotive.integration.client.api.asset.getdrawable.GetDrawableResponse
import com.tomtom.automotive.integration.client.api.model.drawable.Density
import com.tomtom.automotive.integration.client.api.model.guidance.RoadShield
import com.tomtom.automotive.integration.client.common.Callback
import com.tomtom.automotive.integration.client.common.Result
private const val TAG = "Guidance"
fun fetchRoadShieldAsset(assetManager: AssetManager, roadShield: RoadShield) {
val drawableHandle = roadShield.getDrawableHandle(Density(2f))
assetManager.getDrawable(
GetDrawableParameters(drawableHandle),
object : GetDrawableCallback {
override fun onResult(result: Result<GetDrawableResponse, GetDrawableFailure>) {
when (result) {
is Result.Success -> {
val drawableResource = result.value.drawable
Log.d(TAG, "Road shield fetched: $drawableResource")
}
is Result.Failure -> {
Log.e(TAG, "Failed to fetch road shield: ${result.failure}")
}
}
}
override fun onFunctionalityUnavailable(reason: Callback.Reason) {
Log.e(TAG, "Asset manager unavailable: ${reason.devMessage}")
}
}
)
}

Audio announcements

The Instruction object includes an audioAnnouncementPhase field that indicates the timing phase of the audio guidance:

import android.util.Log
import com.tomtom.automotive.integration.client.api.guidance.GuidanceManager
import com.tomtom.automotive.integration.client.api.guidance.observenextinstruction.InstructionInfo
import com.tomtom.automotive.integration.client.api.guidance.observenextinstruction.NextInstructionListener
import com.tomtom.automotive.integration.client.api.model.guidance.AudioAnnouncementPhase
import com.tomtom.automotive.integration.client.common.Callback
import com.tomtom.automotive.integration.client.common.SdkReleasable
private const val TAG = "Guidance"
private var observeAudioReleasable: SdkReleasable? = null
fun observeAudioAnnouncements(guidanceManager: GuidanceManager) {
observeAudioReleasable = guidanceManager.observeNextInstruction(
object : NextInstructionListener {
override fun onNextInstructionChange(instructionInfo: InstructionInfo) {
val instruction = instructionInfo.instruction
if (instruction != null) {
val phase = instruction.audioAnnouncementPhase
when (phase) {
AudioAnnouncementPhase.FOLLOW -> {
Log.d(TAG, "Audio: Follow instruction")
// Play follow announcement
}
AudioAnnouncementPhase.FAR_AWAY -> {
Log.d(TAG, "Audio: Far away announcement")
// Play far away announcement
}
AudioAnnouncementPhase.EARLY -> {
Log.d(TAG, "Audio: Early announcement")
// Play early announcement
}
AudioAnnouncementPhase.MAIN -> {
Log.d(TAG, "Audio: Main announcement")
// Play main announcement
}
AudioAnnouncementPhase.CONFIRMATION -> {
Log.d(TAG, "Audio: Confirmation announcement")
// Play confirmation announcement
}
AudioAnnouncementPhase.UNHANDLED, null -> {
Log.d(TAG, "Audio: No announcement phase")
}
}
}
}
override fun onFunctionalityUnavailable(reason: Callback.Reason) {
Log.e(TAG, "Audio announcements unavailable: ${reason.devMessage}")
}
}
)
}
fun unObserveAudioAnnouncements() {
observeAudioReleasable?.release()
observeAudioReleasable = null
}

Audio announcement phases

The AudioAnnouncementPhase enum represents different timing phases for audio guidance:

  • FOLLOW - Announcement at any distance beyond far away
  • FAR_AWAY - Earliest announcement about upcoming maneuver
  • EARLY - Prepare for upcoming maneuver
  • MAIN - Short time before the maneuver
  • CONFIRMATION - At the time of the maneuver itself

Lane guidance

Lane guidance helps drivers choose the correct lane for upcoming maneuvers:

import android.util.Log
import com.tomtom.automotive.integration.client.api.guidance.GuidanceManager
import com.tomtom.automotive.integration.client.api.guidance.observenextlaneguidance.LaneGuidanceInfo
import com.tomtom.automotive.integration.client.api.guidance.observenextlaneguidance.NextLaneGuidanceListener
import com.tomtom.automotive.integration.client.common.Callback
import com.tomtom.automotive.integration.client.common.SdkReleasable
private const val TAG = "Guidance"
private var observeNextLaneGuidanceReleasable: SdkReleasable? = null
fun observeNextLaneGuidance(guidanceManager: GuidanceManager) {
observeNextLaneGuidanceReleasable = guidanceManager.observeNextLaneGuidance(
object : NextLaneGuidanceListener {
override fun onNextLaneGuidanceChange(laneGuidanceInfo: LaneGuidanceInfo) {
val lanes = laneGuidanceInfo.lanes
Log.d(TAG, "Lane guidance: ${lanes.size} lanes")
lanes.forEachIndexed { index, lane ->
lane.laneDirections.forEach { direction ->
val marking = direction.laneMarking
val shouldFollow = direction.hasToBeFollowed
Log.d(TAG, "Lane $index: $marking (follow: $shouldFollow)")
}
}
}
override fun onFunctionalityUnavailable(reason: Callback.Reason) {
Log.e(TAG, "Lane guidance unavailable: ${reason.devMessage}")
}
}
)
}
fun unObserveNextLaneGuidance() {
observeNextLaneGuidanceReleasable?.release()
observeNextLaneGuidanceReleasable = null
}

Lane marking types

The LaneMarking enum represents the direction arrow or marking for each lane:

  • STRAIGHT
  • SLIGHT_RIGHT
  • RIGHT
  • SHARP_RIGHT
  • RIGHT_U_TURN
  • SLIGHT_LEFT
  • LEFT
  • SHARP_LEFT
  • LEFT_U_TURN