NavigationRouteAddObserver
public protocol NavigationRouteAddObserver : Observer
Declares an observer that can receive a route has been added to the navigation session.
A new route can be added to the session under the following circumstances:
- When navigation has started with a route using the
start()
method withNavigationOptions
as an argument. - When navigation is updated using the
setActiveRoutePlan(_:)
method. Note, if the new route is identical, which means it has the sameRoute/id
as the current active route, it will not notify the observer. - When navigation finds a better route and the
TomTomSDKNavigationEngines/BetterProposalAcceptanceMode
is set to eitherTomTomSDKNavigationEngines/BetterProposalAcceptanceMode/manual
orTomTomSDKNavigationEngines/BetterProposalAcceptanceMode/unreachableOnly
. - When navigation finds a reachable route and
TomTomSDKNavigationEngines/BetterProposalAcceptanceMode
is set toTomTomSDKNavigationEngines/BetterProposalAcceptanceMode/manual
. - When navigation finds a reachable route, due to the navigated route being unreachable, and
TomTomSDKNavigationEngines/BetterProposalAcceptanceMode
is set toTomTomSDKNavigationEngines/BetterProposalAcceptanceMode/unreachableOnly
so that the reachable route is automatically applied. - When the
TomTomSDKNavigationEngines/BetterProposalAcceptanceMode
is set toTomTomSDKNavigationEngines/BetterProposalAcceptanceMode/automatic
and the proposed route is automatically applied. - When navigation automatically replans and adds the newly planned route to the session.
- When the
preferredLanguage
is set and the replanning with the new language has completed.
To receive notifications of a route being added to the session, first implement an observer object that conforms to NavigationRouteAddObserver
, for example:
class CustomRouteObserver: NavigationRouteAddObserver { ... }
In order to complete conformance, the observer object must implement the following callback:
func didAddRoute(route: options: reason:) {
// add code here that handles the route being added to the session
}
This callback function could render the newly added route on the map, for example.
Next, add this observer with navigation using addRouteAddObserver(_:)
.
To stop notifications of a route being added to the session, remove the observer using removeRouteAddObserver(_:)
.
Please note that NavigationRouteAddObserver
is notified only when the replanned route differs from the current active route in terms of geometry.
Events like route refresh and increment update of guidance instructions will not notify this observer.
For these scenarios the NavigationRouteUpdateObserver
is notified.
The complementary observer that notifies on the removal of routes from the session is NavigationRouteRemoveObserver
.
Important
The addition of a route to the session does not necessarily make it active. To receive notifications of changes to the active route, use theNavigationActiveRouteChangeObserver
.
-
Notifies when a
Route
has been added to the navigation session.Declaration
Swift
func didAddRoute(route: Route, options: RoutePlanningOptions, reason: RouteAddedReason)
Parameters
route
The
Route
that has been added to the navigation session.options
The
RoutePlanningOptions
that has been used forRoute
.reason
The reason for adding the
Route
.