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.

  • 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 to true 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 selected routeIndex 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 of routes remain unchanged comparing to original indexedRouteResponse. 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.

  • Declaration

    Swift

    @discardableResult
    public func refreshRoute(indexedRouteResponse: IndexedRouteResponse,
                             fromLegAtIndex startLegIndex: UInt32,
                             currentRouteShapeIndex: Int,
                             currentLegShapeIndex: Int,
                             completionHandler: @escaping Directions.RouteCompletionHandler) -> NavigationProviderRequest?