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

    options

    A MatrixOptions object representing the request parameter options.

    credentials

    A 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>) -> Void

    Parameters

    session

    A Matrix.Session object containing session information

    result

    A Result enum 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 MBXAccessToken key 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

    credentials

    Credentials that will be used to make API requests to Mapbox Matrix API.

    urlSession

    URLSession that will be used to submit API requests to Mapbox Matrix API.

    processingQueue

    A 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) -> URLSessionDataTask

    Parameters

    options

    A MatrixOptions object specifying the requirements for the resulting matrices.

    completionHandler

    The 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.