NavigationServiceDelegate

A navigation service delegate interacts with one or more NavigationService instances (such as MapboxNavigationService objects) during turn-by-turn navigation. This protocol is the main way that your application can synchronize its state with the SDK’s location-related functionality. Each of the protocol’s methods is optional.

As the user progresses along a route, a navigation service informs its delegate about significant events as they occur, and the delegate has opportunities to influence the route and its presentation. For example, when the navigation service reports that the user has arrived at the destination, your delegate implementation could present information about the destination. It could also customize individual visual or spoken instructions along the route by returning modified instruction objects.

Assign a NavigationServiceDelegate instance to the NavigationService.delegate property of the navigation service before you start the service.

The RouterDelegate protocol defines corresponding methods so that a Router instance can interact with an object that is both a router delegate and a navigation service, which in turn interacts with a navigation service delegate. Additionally, several location-related methods in this protocol have corresponding methods in the NavigationViewControllerDelegate protocol, which can be convenient if you are using the navigation service in conjunction with a NavigationViewController. Normally, you would either implement methods in NavigationServiceDelegate or NavigationViewControllerDelegate but not RouterDelegate.

Seealso

NavigationViewControllerDelegate

Seealso

RouterDelegate
  • Returns whether the navigation service should be allowed to calculate a new route.

    If implemented, this method is called as soon as the navigation service detects that the user is off the predetermined route. Implement this method to conditionally prevent rerouting. If this method returns true, navigationService(_:willRerouteFrom:) will be called immediately afterwards.

    Note

    This delegate method includes a default implementation that prints a warning to the console when this method is called. See UnimplementedLogging for details.

    Default Implementation

  • navigationService(_:willRerouteFrom:) Default implementation

    Called immediately before the navigation service calculates a new route.

    This method is called after navigationService(_:shouldRerouteFrom:) is called, simultaneously with the NavigationServiceWillReroute notification being posted, and before navigationService(_:didRerouteAlong:) is called.

    Note

    This delegate method includes a default implementation that prints a warning to the console when this method is called. See UnimplementedLogging for details.

    Default Implementation

  • navigationService(_:shouldDiscard:) Default implementation

    Called when a location has been identified as unqualified to navigate on.

    See CLLocation.isQualified for more information about what qualifies a location.

    Note

    This delegate method includes a default implementation that prints a warning to the console when this method is called. See UnimplementedLogging for details.

    Default Implementation

  • Called immediately after the navigation service receives a new route.

    This method is called after navigationService(_:willRerouteFrom:) and simultaneously with the NavigationServiceDidReroute notification being posted.

    Note

    This delegate method includes a default implementation that prints a warning to the console when this method is called. See UnimplementedLogging for details.

    Default Implementation

  • Called when the navigation service fails to receive a new route.

    This method is called after navigationService(_:willRerouteFrom:) and simultaneously with the NavigationServiceDidFailToReroute notification being posted.

    Note

    This delegate method includes a default implementation that prints a warning to the console when this method is called. See UnimplementedLogging for details.

    Default Implementation

  • Called when the navigation service updates the route progress model.

    Note

    This delegate method includes a default implementation that prints a warning to the console when this method is called. See UnimplementedLogging for details.

    Default Implementation

  • Called when the navigation service detects that the user has passed a point at which an instruction should be displayed.

    Note

    This delegate method includes a default implementation that prints a warning to the console when this method is called. See UnimplementedLogging for details.

    Default Implementation

  • Called when the navigation service detects that the user has passed a point at which an instruction should be spoken.

    Note

    This delegate method includes a default implementation that prints a warning to the console when this method is called. See UnimplementedLogging for details.

    Default Implementation

  • Called as the navigation service approaches a waypoint.

    This message is sent, once per progress update, as the user is approaching a waypoint. You can use this to cue UI, to do network pre-loading, etc.

    Important

    This method will likely be called several times as you approach a destination. If only one consumption of this method is desired, then usage of an internal flag is recommended.

    Note

    This delegate method includes a default implementation that prints a warning to the console when this method is called. See UnimplementedLogging for details.

    Default Implementation

  • navigationService(_:didArriveAt:) Default implementation

    Called when the navigation service arrives at a waypoint.

    You can implement this method to prevent the navigation service from automatically advancing to the next leg. For example, you can and show an interstitial sheet upon arrival and pause navigation by returning false, then continue the route when the user dismisses the sheet. If this method is unimplemented, the navigation service automatically advances to the next leg when arriving at a waypoint.

    Postcondition

    If you return false, you must manually advance to the next leg: obtain the value of the routeProgress property, then increment the RouteProgress.legIndex property.

    Note

    This delegate method includes a default implementation that prints a warning to the console when this method is called. See UnimplementedLogging for details.

    Default Implementation

  • Called when the navigation service arrives at a waypoint.

    You can implement this method to allow the navigation service to continue check and reroute the user if needed. By default, the user will not be rerouted when arriving at a waypoint.

    Note

    This delegate method includes a default implementation that prints a warning to the console when this method is called. See UnimplementedLogging for details.

    Default Implementation

  • Called when the navigation service will disable battery monitoring.

    Implementing this method will allow developers to change whether battery monitoring is disabled when NavigationService is deinited.

    Note

    This delegate method includes a default implementation that prints a warning to the console when this method is called. See UnimplementedLogging for details.

    Default Implementation

  • Called when the navigation service is about to begin location simulation.

    Implementing this method will allow developers to react when “poor GPS” location-simulation is about to start, possibly to show a “Poor GPS” banner in the UI.

    Note

    This delegate method includes a default implementation that prints a warning to the console when this method is called. See UnimplementedLogging for details.

    Default Implementation

  • Called after the navigation service begins location simulation.

    Implementing this method will allow developers to react when “poor GPS” location-simulation has started, possibly to show a “Poor GPS” banner in the UI.

    Note

    This delegate method includes a default implementation that prints a warning to the console when this method is called. See UnimplementedLogging for details.

    Default Implementation

  • Called when the navigation service is about to end location simulation.

    Implementing this method will allow developers to react when “poor GPS” location-simulation is about to end, possibly to hide a “Poor GPS” banner in the UI.

    Note

    This delegate method includes a default implementation that prints a warning to the console when this method is called. See UnimplementedLogging for details.

    Default Implementation

  • Called after the navigation service ends location simulation.

    Implementing this method will allow developers to react when “poor GPS” location-simulation has ended, possibly to hide a “Poor GPS” banner in the UI.

    Note

    This delegate method includes a default implementation that prints a warning to the console when this method is called. See UnimplementedLogging for details.

    Default Implementation