Directions
open class Directions : NSObjectextension Directions: OfflineDirectionsProtocolA Directions object provides you with optimal directions between different locations, or waypoints. The directions object passes your request to the Mapbox Directions API and returns the requested information to a closure (block) that you provide. A directions object can handle multiple simultaneous requests. A RouteOptions object specifies criteria for the results, such as intermediate waypoints, a mode of transportation, or the level of detail to be returned.
Each result produced by the directions object is stored in a Route object. Depending on the RouteOptions object you provide, each route may include detailed information suitable for turn-by-turn directions, or it may include only high-level information such as the distance, estimated travel time, and name of each leg of the trip. The waypoints that form the request may be conflated with nearby locations, as appropriate; the resulting waypoints are provided to the closure.
- 
                  
                  A tuple type representing the direction session that was generated from the request. DeclarationSwift public typealias Session = (options: DirectionsOptions, credentials: DirectionsCredentials)ParametersoptionsA DirectionsOptionsobject representing the request parameter options.credentialsA object containing the credentials used to make the request. 
- 
                  
                  A closure (block) to be called when a directions request is complete. DeclarationSwift public typealias RouteCompletionHandler = (_ session: Session, _ result: Result<RouteResponse, DirectionsError>) -> VoidParameterssessionA Directions.Sessionobject containing session informationresultA Resultenum that represents theRouteResponseif the request returned successfully, or the error if it did not.
- 
                  
                  A closure (block) to be called when a map matching request is complete. DeclarationSwift public typealias MatchCompletionHandler = (_ session: Session, _ result: Result<MapMatchingResponse, DirectionsError>) -> VoidParameterssessionA Directions.Sessionobject containing session informationresultA Resultenum that represents theMapMatchingResponseif the request returned successfully, or the error if it did not.
- 
                  
                  A closure (block) to be called when a directions refresh request is complete. Postcondition To update the original route, pass RouteRefreshResponse.routeinto theRoute.refreshLegAttributes(from:)method.DeclarationSwift public typealias RouteRefreshCompletionHandler = (_ credentials: DirectionsCredentials, _ result: Result<RouteRefreshResponse, DirectionsError>) -> VoidParameterscredentialsAn object containing the credentials used to make the request. resultA Resultenum that represents theRouteRefreshResponseif the request returned successfully, or the error if it did not.
- 
                  
                  The shared directions object. To use this object, a Mapbox access token should be specified in the MGLMapboxAccessTokenkey in the main application bundle’s Info.plist.DeclarationSwift public static let shared: Directions
- 
                  
                  The Authorization & Authentication credentials that are used for this service. If nothing is provided, the default behavior is to read credential values from the developer’s Info.plist. DeclarationSwift public let credentials: DirectionsCredentials
- 
                  
                  Initializes a newly created directions object with an optional access token and host. DeclarationSwift public init(credentials: DirectionsCredentials = .init())ParameterscredentialsA DirectionsCredentialsobject that, optionally, contains customized Token and Endpoint information. If no credentials object is supplied, then defaults are used.
- 
                  
                  Begins asynchronously calculating routes using the given options and delivers the results to a closure. This method retrieves the routes asynchronously from the Mapbox Directions 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. Routes may be displayed atop a Mapbox map. DeclarationSwift @discardableResult open func calculate(_ options: RouteOptions, completionHandler: @escaping RouteCompletionHandler) -> URLSessionDataTaskParametersoptionsA RouteOptionsobject specifying the requirements for the resulting routes.completionHandlerThe closure (block) to call with the resulting routes. This closure is executed on the application’s main thread. Return ValueThe data task used to perform the HTTP request. If, while waiting for the completion handler to execute, you no longer want the resulting routes, cancel this task. 
- 
                  
                  Begins asynchronously calculating matches using the given options and delivers the results to a closure. This method retrieves the matches asynchronously from the Mapbox Map Matching 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. To get Routes based on these matches, use thecalculateRoutes(matching:completionHandler:)method instead.DeclarationSwift @discardableResult open func calculate(_ options: MatchOptions, completionHandler: @escaping MatchCompletionHandler) -> URLSessionDataTaskParametersoptionsA MatchOptionsobject specifying the requirements for the resulting matches.completionHandlerThe closure (block) to call with the resulting matches. This closure is executed on the application’s main thread. Return ValueThe data task used to perform the HTTP request. If, while waiting for the completion handler to execute, you no longer want the resulting matches, cancel this task. 
- 
                  
                  Begins asynchronously calculating routes that match the given options and delivers the results to a closure. This method retrieves the routes asynchronously from the Mapbox Map Matching 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. To get the Matches that these routes are based on, use thecalculate(_:completionHandler:)method instead.DeclarationSwift @discardableResult open func calculateRoutes(matching options: MatchOptions, completionHandler: @escaping RouteCompletionHandler) -> URLSessionDataTaskParametersoptionsA MatchOptionsobject specifying the requirements for the resulting match.completionHandlerThe closure (block) to call with the resulting routes. This closure is executed on the application’s main thread. Return ValueThe data task used to perform the HTTP request. If, while waiting for the completion handler to execute, you no longer want the resulting routes, cancel this task. 
- 
                  
                  Begins asynchronously refreshing the route with the given identifier, optionally starting from an arbitrary leg along the route. 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.refreshingEnabledtotruewhen calculating the original route.DeclarationSwift @discardableResult open func refreshRoute(responseIdentifier: String, routeIndex: Int, fromLegAtIndex startLegIndex: Int = 0, completionHandler: @escaping RouteRefreshCompletionHandler) -> URLSessionDataTask?ParametersresponseIdentifierThe RouteResponse.identifiervalue of theRouteResponsethat contains the route to refresh. You can alternatively use the value ofRoute.routeIdentifier.routeIndexThe index of the route to refresh in the original RouteResponse.routesarray.startLegIndexThe 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. completionHandlerThe closure (block) to call with the resulting skeleton route data. This closure is executed on the application’s main thread. Return ValueThe data task used to perform the HTTP request. If, while waiting for the completion handler to execute, you no longer want the resulting skeleton routes, cancel this task. 
- 
                  
                  The GET HTTP URL used to fetch the routes from the API. After requesting the URL returned by this method, you can parse the JSON data in the response and pass it into the Route.init(json:waypoints:profileIdentifier:)initializer. Alternatively, you can use thecalculate(_:options:)method, which automatically sends the request and parses the response.DeclarationSwift open func url(forCalculating options: DirectionsOptions) -> URLParametersoptionsA DirectionsOptionsobject specifying the requirements for the resulting routes.Return ValueThe URL to send the request to. 
- 
                  
                  The HTTP URL used to fetch the routes from the API using the specified HTTP method. The query part of the URL is generally suitable for GET requests. However, if the URL is exceptionally long, it may be more appropriate to send a POST request to a URL without the query part, relegating the query to the body of the HTTP request. Use the urlRequest(forCalculating:)method to get an HTTP request that is a GET or POST request as necessary.After requesting the URL returned by this method, you can parse the JSON data in the response and pass it into the Route.init(json:waypoints:profileIdentifier:)initializer. Alternatively, you can use thecalculate(_:options:)method, which automatically sends the request and parses the response.DeclarationSwift open func url(forCalculating options: DirectionsOptions, httpMethod: String) -> URLParametersoptionsA DirectionsOptionsobject specifying the requirements for the resulting routes.httpMethodThe HTTP method to use. The value of this argument should match the URLRequest.httpMethodof the request you send. Currently, only GET and POST requests are supported by the API.Return ValueThe URL to send the request to. 
- 
                  
                  The HTTP request used to fetch the routes from the API. The returned request is a GET or POST request as necessary to accommodate URL length limits. After sending the request returned by this method, you can parse the JSON data in the response and pass it into the Route.init(json:waypoints:profileIdentifier:)initializer. Alternatively, you can use thecalculate(_:options:)method, which automatically sends the request and parses the response.DeclarationSwift open func urlRequest(forCalculating options: DirectionsOptions) -> URLRequestParametersoptionsA DirectionsOptionsobject specifying the requirements for the resulting routes.Return ValueA GET or POST HTTP request to calculate the specified options. 
- 
                  
                  The URL to a list of available versions. DeclarationSwift public var availableVersionsURL: URL { get }
- 
                  
                  Returns the URL to generate and download a tile pack from the Route Tiles API. DeclarationSwift public func tilesURL(for coordinateBounds: BoundingBox, version: OfflineVersion) -> URLParameterscoordinateBoundsThe coordinate bounds that the tiles should cover. versionA version obtained from availableVersionsURL.Return ValueThe URL to generate and download the tile pack that covers the coordinate bounds. 
- 
                  
                  Fetches the available offline routing tile versions and returns them in descending chronological order. The most recent version should typically be passed into downloadTiles(in:version:completionHandler:).DeclarationSwift @discardableResult public func fetchAvailableOfflineVersions(completionHandler: @escaping OfflineVersionsHandler) -> URLSessionDataTaskParameterscompletionHandlerA closure of type OfflineVersionsHandlerwhich will be called when the request completes
- 
                  
                  Downloads offline routing tiles of the given version within the given coordinate bounds using the shared URLSession. The tiles are written to disk at the location passed into the completionHandler.DeclarationSwift @discardableResult public func downloadTiles(in coordinateBounds: BoundingBox, version: OfflineVersion, completionHandler: @escaping OfflineDownloaderCompletionHandler) -> URLSessionDownloadTaskParameterscoordinateBoundsThe bounding box versionThe version to download. Version is represented as a String (yyyy-MM-dd-x) completionHandlerA closure of type OfflineDownloaderCompletionHandlerwhich will be called when the request completes
 Install in Dash
              Install in Dash
             Directions Class Reference
        Directions Class Reference