GuidanceUpdateObserver
public protocol GuidanceUpdateObserver : Observer
Informs the caller about announcements and instructions update events.
The method TomTomSDKNavigationEngines.GuidanceEngine.generateGuidance(navigationSnapshot:)
generates the guidance with instructions and distance.
Based on the guidance result, the methods of the observers 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(_:)
.
-
Called when the next instructions change.
This method is invoked whenever there’s an update of the next instructions.
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.
-
Called when an 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 propertyGuidanceEngine.announcementsEnabled
set tofalse
, 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 triggered.
-
Called with each location update that changes the distance to the instruction.
This method is called whenever the location update modifies 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.