GuidanceUpdateObserver

public protocol GuidanceUpdateObserver : Observer

Declares an observer that can receive announcements and instruction update events.

The method TomTomSDKNavigationEngines.GuidanceEngine.generateGuidance(navigationSnapshot:) generates the guidance with instructions and distance. Based on the guidance result, appropriate observer methods are called.

The protocol provides the interface for handling several events like changes in instructions, generation of announcements, and changes in distance to the next instruction.

To observe the guidance changes, first implement this interface to create an observer, for example:

class CustomGuidanceUpdateObserver: GuidanceUpdateObserver {

    func didChangeInstructions(instructions: [GuidanceInstruction]) {
        // Add code here that handles the changes of instructions.
    }

    func didGenerateAnnouncement(announcement: GuidanceAnnouncement, shouldPlay: Bool) {
        // Add code here that handles a new generate announcement.
    }

    func didChangeDistanceToNextInstruction(
        distance: Measurement<UnitLength>,
        instructions: [GuidanceInstruction],
        currentPhase: InstructionPhase
    ) {
        // Add code here that handles a change of distance to new instruction.
    }
}

Then add the observer using addGuidanceUpdateObserver(_:). To stop observation of the guidance changes, remove the observer using removeGuidanceUpdateObserver(_:).

  • Notifies that the next instructions have been changed.

    Declaration

    Swift

    func didChangeInstructions(instructions: [GuidanceInstruction])

    Parameters

    instructions

    The ordered list of next instructions along the route. The number of instructions provided is determined by the internal threshold.

  • Notifies that the announcement about the upcoming maneuver is generated.

    The announcement is generated based on the distance to maneuver, current instruction and the next instruction. Configure the announcement verbosity by changing the property GuidanceEngine.announcementMode. If the property GuidanceEngine.announcementsEnabled set to false, this method will not be invoked.

    Declaration

    Swift

    func didGenerateAnnouncement(announcement: GuidanceAnnouncement, shouldPlay: Bool)

    Parameters

    announcement

    Announcement about the upcoming maneuver.

    shouldPlay

    Whether the announcement should be played.

  • Notifies with each location update that changes the distance to the instruction.

    Notifies that the distance to the next instruction has been changed when the location update changes the distance to the upcoming instruction

    Declaration

    Swift

    func didChangeDistanceToNextInstruction(
        distance: Measurement<UnitLength>,
        instructions: [GuidanceInstruction],
        currentPhase: InstructionPhase
    )

    Parameters

    distance

    The updated distance to the next instruction. This provides the remaining distance to the next instruction.

    instructions

    The ordered list of next instructions along the route. The internal threshold determines the number of instructions provided.

    currentPhase

    The current phase of the instruction. The value indicates the stage of the current instruction.