Router
public protocol Router : CLLocationManagerDelegate
A class conforming to the Router
protocol tracks the user’s progress as they travel along a predetermined route. It calls methods on its delegate
, which conforms to the RouterDelegate
protocol, whenever significant events or decision points occur along the route. Despite its name, this protocol does not define the interface of a routing engine.
There are two concrete implementations of the Router
protocol. RouteController
, the default implementation, is capable of client-side routing and depends on the Mapbox Navigation Native framework. LegacyRouteController
is an alternative implementation that does not have this dependency but must be used in conjunction with the Mapbox Directions API over a network connection.
-
The route controller’s associated location manager.
Declaration
Swift
var dataSource: RouterDataSource { get }
-
The route controller’s delegate.
Declaration
Swift
var delegate: RouterDelegate? { get set }
-
Intializes a new
RouteController
.Declaration
Swift
@available(*, deprecated, renamed: "init(alongRouteAtIndex:in:options:customRoutingProvider:dataSource:﹚") init(alongRouteAtIndex routeIndex: Int, in routeResponse: RouteResponse, options: RouteOptions, routingProvider: RoutingProvider, dataSource source: RouterDataSource)
Parameters
routeIndex
The index of the route within the original
RouteResponse
object.routeResponse
RouteResponse
object, containing selection of routes to follow.routingProvider
RoutingProvider
, used to create a route during refreshing or rerouting.source
The data source for the RouteController.
-
Intializes a new
RouteController
.Declaration
Swift
init(alongRouteAtIndex routeIndex: Int, in routeResponse: RouteResponse, options: RouteOptions, customRoutingProvider: RoutingProvider?, dataSource source: RouterDataSource)
Parameters
routeIndex
The index of the route within the original
RouteResponse
object.routeResponse
RouteResponse
object, containing selection of routes to follow.customRoutingProvider
Custom
RoutingProvider
, used to create a route during refreshing or rerouting.source
The data source for the RouteController.
-
RoutingProvider
, used to create a route during refreshing or rerouting.Declaration
Swift
@available(*, deprecated, renamed: "customRoutingProvider") var routingProvider: RoutingProvider { get }
-
Custom
RoutingProvider
, used to create a route during refreshing or rerouting.Declaration
Swift
var customRoutingProvider: RoutingProvider? { get }
-
Details about the user’s progress along the current route, leg, and step.
Declaration
Swift
var routeProgress: RouteProgress { get }
-
The route along which the user is expected to travel.
You can update the route using
Router.updateRoute(with:routeOptions:completion:)
.Declaration
Swift
var route: Route { get }
-
The
RouteResponse
containing the route along which the user is expected to travel, plus its index in thisRouteResponse
, if applicable.If you want to update the route use
Router.updateRoute(with:routeOptions:completion:)
method.Declaration
Swift
var indexedRouteResponse: IndexedRouteResponse { get }
-
Given a users current location, returns a Boolean whether they are currently on the route.
If the user is not on the route, they should be rerouted.
Declaration
Swift
func userIsOnRoute(_ location: CLLocation) -> Bool
-
A radius around the current user position in which the API will avoid returning any significant maneuvers when rerouting.
Provided
TimeInterval
value will be converted to meters using current speed. Default value is8 seconds
.Declaration
Swift
var initialManeuverAvoidanceRadius: TimeInterval { get set }
-
The idealized user location. Snapped to the route line, if applicable, otherwise raw or nil.
Declaration
Swift
var location: CLLocation? { get }
-
The most recently received user location.
Note
This is a raw location received fromlocationManager
. To obtain an idealized location, use thelocation
property.Declaration
Swift
var rawLocation: CLLocation? { get }
-
The most recently received user heading, if any.
Declaration
Swift
var heading: CLHeading? { get }
-
If true, the
RouteController
attempts to calculate a more optimal route for the user on an interval defined byRouteControllerProactiveReroutingInterval
. IfrefreshesRoute
is enabled too, reroute attempt will be fired after route refreshing.Declaration
Swift
var reroutesProactively: Bool { get set }
-
If true, the
RouteController
attempts to update ETA and route congestion on an interval defined byRouteControllerProactiveReroutingInterval
.Refreshing will be used only if route’s mode of transportation profile is set to
.automobileAvoidingTraffic
. IfreroutesProactively
is enabled too, rerouting will be checked after route is refreshed.Declaration
Swift
var refreshesRoute: Bool { get set }
-
Advances the leg index.
This is a convienence method provided to advance the leg index of any given router without having to worry about the internal data structure of the router.
Declaration
Swift
func advanceLegIndex(completionHandler: AdvanceLegCompletionHandler?)
-
Asynchronously replaces currently active route with the provided
IndexedRouteResponse
.You can use this method to perform manual reroutes.
delegate
will be notified about route change viaRouterDelegate.router(router:willRerouteFrom:)
andRouterDelegate.router(_:didRerouteAlong:at:proactive:)
methods.Declaration
Swift
func updateRoute(with indexedRouteResponse: IndexedRouteResponse, routeOptions: RouteOptions?, completion: ((Bool) -> Void)?)
Parameters
indexedRouteResponse
A
MapboxDirections.RouteResponse
object with a new route along with its index in routes array.routeOptions
Route options used to create the route. You can pass nil to reuse the
RouteOptions
from the currently active route. If the newindexedRoute
is for a different set of waypoints,routeOptions
are required.completion
A completion that will be called when when a new route is applied with a boolean indicating whether the change was successful. Until completion is called
routeProgress
will represent the old route. -
Forcefully stop navigation process without ability to continue it.
Use this method to indicate that you no longer need navigation experience for current session/UI. After finishing,
Router
will not be able to update route, route leg, issue a reroute or do any other update, related to route traversing.Declaration
Swift
func finishRouting()
-
AlternativeRoute
s user might take during this trip to reach the destination using another road.Array contents are updated automatically duting the trip. Alternative routes may be slower or longer then the main route. To get updates, subscribe to
RouterDelegate.router(_:didUpdateAlternatives:removedAlternatives:)
orNotification.Name.routeControllerDidUpdateAlternatives
notification.Declaration
Swift
var continuousAlternatives: [AlternativeRoute] { get }