Matrix
open class Matrix
Computes distances and durations between origin-destination pairs, and returns the resulting distances in meters and durations in seconds.
-
A tuple type representing the matrix session that was generated from the request.
Declaration
Swift
public typealias Session = (options: MatrixOptions, credentials: Credentials)Parameters
optionsA
MatrixOptionsobject representing the request parameter options.credentialsA object containing the credentials used to make the request.
-
A closure (block) to be called when a matrix request is complete.
Declaration
Swift
public typealias MatrixCompletionHandler = (_ session: Session, _ result: Result<MatrixResponse, MatrixError>) -> VoidParameters
sessionA
Matrix.Sessionobject containing session informationresultA
Resultenum that represents the (RETURN TYPE) if the request returned successfully, or the error if it did not.
-
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.
Declaration
Swift
public let credentials: Credentials -
The shared matrix object.
To use this object, a Mapbox access token should be specified in the
MBXAccessTokenkey in the main application bundle’s Info.plist.Declaration
Swift
public static let shared: Matrix -
Creates a new instance of Matrix object.
Declaration
Swift
public init(credentials: Credentials = .init(), urlSession: URLSession = .shared, processingQueue: DispatchQueue = .global(qos: .userInitiated))Parameters
credentialsCredentials that will be used to make API requests to Mapbox Matrix API.
urlSessionURLSession that will be used to submit API requests to Mapbox Matrix API.
processingQueueA DispatchQueue that will be used for CPU intensive work.
-
Begins asynchronously calculating matrices using the given options and delivers the results to a closure.
This method retrieves the matrices asynchronously from the Mapbox Matrix 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 contours.
Declaration
Swift
@discardableResult open func calculate(_ options: MatrixOptions, completionHandler: @escaping MatrixCompletionHandler) -> URLSessionDataTaskParameters
optionsA
MatrixOptionsobject specifying the requirements for the resulting matrices.completionHandlerThe closure (block) to call with the resulting matrices. This closure is executed on the application’s main thread.
Return Value
The data task used to perform the HTTP request. If, while waiting for the completion handler to execute, you no longer want the resulting matrices, cancel this task.
-
The GET HTTP URL used to fetch the matrices from the Matrix API.
Declaration
Swift
open func url(forCalculating options: MatrixOptions) -> URLParameters
optionsA
MatrixOptionsobject specifying the requirements for the resulting contours.Return Value
The URL to send the request to.
-
The HTTP request used to fetch the matrices from the Matrix API.
Declaration
Swift
open func urlRequest(forCalculating options: MatrixOptions) -> URLRequestParameters
optionsA
MatrixOptionsobject specifying the requirements for the resulting routes.Return Value
A GET HTTP request to calculate the specified options.
Install in Dash
Matrix Class Reference