NavigationRouteAddedObserver

public protocol NavigationRouteAddedObserver : Observer

Informs the caller that 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 with NavigationOptions as an argument.
  • When navigation is updated using the update(navigationOptions:) method. Note, if the new route is identical, which means it has the same Route/id as the current active route, it will not trigger the observer.
  • When navigation finds a better route and the TomTomSDKNavigationEngines/BetterProposalAcceptanceMode is set to either TomTomSDKNavigationEngines/BetterProposalAcceptanceMode/manual or TomTomSDKNavigationEngines/BetterProposalAcceptanceMode/unreachableOnly.
  • When navigation finds a reachable route and TomTomSDKNavigationEngines/BetterProposalAcceptanceMode is set to TomTomSDKNavigationEngines/BetterProposalAcceptanceMode/manual.
  • When navigation finds a reachable route, due to the navigated route being unreachable, and TomTomSDKNavigationEngines/BetterProposalAcceptanceMode is set to TomTomSDKNavigationEngines/BetterProposalAcceptanceMode/unreachableOnly so that the reachable route is automatically applied.
  • When the TomTomSDKNavigationEngines/BetterProposalAcceptanceMode is set to TomTomSDKNavigationEngines/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 NavigationRouteAddedObserver, for example:

class RouteObserver: NavigationRouteAddedObserver { ... }

In order to complete conformance, the observer object must implement the following callback:

func didAddRoute(route: 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, register this observer with navigation using addRouteAddedObserver(_:). To stop notifications of a route being added to the session, unregister the observer using removeRouteAddedObserver(_:).

Please note that NavigationRouteAddedObserver is triggered 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 trigger this observer. For these scenarios the NavigationRouteUpdateObserver is called.

The complementary observer that notifies on the removal of routes from the session is NavigationRouteRemovedObserver.

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 the NavigationActiveRouteChangedObserver.

Important

This is a Public Preview API. It may be changed or removed at any time.