MapboxRoutingProvider
public class MapboxRoutingProvider : RoutingProvider
Provides alternative access to routing API.
Use this class instead Directions
requests wrapper to request new routes or refresh an existing one. Depending on RouterSource
, MapboxRoutingProvider
will use online and/or onboard routing engines. This may be used when designing purely online or offline apps, or when you need to provide best possible service regardless of internet collection.
-
Initializes new
MapboxRoutingProvider
.Declaration
Swift
public init(_ source: Source = .hybrid, settings: NavigationSettings = .shared, datasetProfileIdentifier: ProfileIdentifier? = nil)
Parameters
source
routing engine source to use.
settings
settings object, used to get credentials and cache configuration.
datasetProfileIdentifier
profile setting, used for selecting tiles type for navigation. If set to
nil
(default) - will detect the same profile as used for current navigation.
-
Configured routing engine source.
Declaration
Swift
public let source: Source
-
Defines source of routing engine to be used for requests.
See moreDeclaration
Swift
public enum Source
-
Profile setting, used for selecting tiles type for navigation.
Declaration
Swift
public let datasetProfileIdentifier: ProfileIdentifier?
-
Unique identifier for a giver request.
Valid only for the same instance of
MapboxRoutingProvider
that issued it.Declaration
Swift
public typealias RequestId = UInt64
-
A request handler for the ongoing routing action.
You can use this instance to cancel ongoing task if needed. Retaining this handler will keep related
See moreMapboxRoutingProvider
from deallocating.Declaration
Swift
public struct Request : NavigationProviderRequest
-
List of ongoing tasks for the routing provider.
You can see if provider is busy with something, or use related
Request.cancel()
to cancel requests as needed.
-
Begins asynchronously calculating routes using the given options and delivers the results to a closure.
Depending on configured
RouterSource
, this method may retrieve the routes asynchronously from the Mapbox Directions API over a network connection or use onboard routing engine with available offline data.Routes may be displayed atop a Mapbox map.
Declaration
Swift
@discardableResult public func calculateRoutes(options: RouteOptions, completionHandler: @escaping IndexedRouteResponseCompletionHandler) -> NavigationProviderRequest?
Parameters
options
A
RouteOptions
object specifying the requirements for the resulting routes.completionHandler
The closure (block) to call with the resulting routes. This closure is executed on the application’s main thread.
Return Value
Related request. If, while waiting for the completion handler to execute, you no longer want the resulting routes, cancel corresponding task using this handle or
activeRequests
. -
Begins asynchronously calculating routes using the given options and delivers the results to a closure.
Depending on configured
RouterSource
, this method may retrieve the routes asynchronously from the Mapbox Directions API over a network connection or use onboard routing engine with available offline data.Routes may be displayed atop a Mapbox map.
Declaration
Swift
@available(*, deprecated, renamed: "calculateRoutes(options:completionHandler:﹚") @discardableResult public func calculateRoutes(options: RouteOptions, completionHandler: @escaping Directions.RouteCompletionHandler) -> NavigationProviderRequest?
Parameters
options
A
RouteOptions
object specifying the requirements for the resulting routes.completionHandler
The closure (block) to call with the resulting routes. This closure is executed on the application’s main thread.
Return Value
Related request. If, while waiting for the completion handler to execute, you no longer want the resulting routes, cancel corresponding task using this handle or
activeRequests
. -
Begins asynchronously calculating matches using the given options and delivers the results to a closure.
Depending on configured
RouterSource
, this method may retrieve the matches asynchronously from the Mapbox Map Matching API over a network connection or use onboard routing engine with available offline data.Declaration
Swift
@discardableResult public func calculateRoutes(options: MatchOptions, completionHandler: @escaping Directions.MatchCompletionHandler) -> NavigationProviderRequest?
Parameters
options
A
MatchOptions
object specifying the requirements for the resulting matches.completionHandler
The closure (block) to call with the resulting matches. This closure is executed on the application’s main thread.
Return Value
Related request. If, while waiting for the completion handler to execute, you no longer want the resulting routes, cancel corresponding task using this handle or
activeRequests
.
-
Begins asynchronously refreshing the selected route, optionally starting from an arbitrary leg.
This method retrieves skeleton route data asynchronously from the Mapbox Directions Refresh API over a network connection. If a connection error or server error occurs, details about the error are passed into the given completion handler in lieu of the routes.
Precondition
Set
RouteOptions.refreshingEnabled
totrue
when calculating the original route.Declaration
Swift
@discardableResult public func refreshRoute(indexedRouteResponse: IndexedRouteResponse, fromLegAtIndex startLegIndex: UInt32 = 0, completionHandler: @escaping Directions.RouteCompletionHandler) -> NavigationProviderRequest?
Parameters
indexedRouteResponse
The
RouteResponse
and selectedrouteIndex
in it to be refreshed.fromLegAtIndex
The index of the leg in the route at which to begin refreshing. The response will omit any leg before this index and refresh any leg from this index to the end of the route. If this argument is omitted, the entire route is refreshed.
completionHandler
The closure (block) to call with updated
RouteResponse
data. Order ofroutes
remain unchanged comparing to originalindexedRouteResponse
. This closure is executed on the application’s main thread.Return Value
Related request. If, while waiting for the completion handler to execute, you no longer want the resulting routes, cancel corresponding task using this handle or
activeRequests
. -
refreshRoute(indexedRouteResponse:fromLegAtIndex:currentRouteShapeIndex:currentLegShapeIndex:completionHandler:)
Declaration
Swift
@discardableResult public func refreshRoute(indexedRouteResponse: IndexedRouteResponse, fromLegAtIndex startLegIndex: UInt32, currentRouteShapeIndex: Int, currentLegShapeIndex: Int, completionHandler: @escaping Directions.RouteCompletionHandler) -> NavigationProviderRequest?