DirectionsResult
@objc(MBDirectionsResult)
open class DirectionsResult : NSObject, NSSecureCoding
A DirectionsResult
represents a result returned from either the Mapbox Directions service.
You do not create instances of this class directly. Instead, you receive Route
or Match
objects when you request directions using the Directions.calculate(_:completionHandler:)
or Directions.calculateRoutes(matching:completionHandler:)
method.
-
An array of geographic coordinates defining the path of the route from start to finish.
This array may be
nil
or simplified depending on therouteShapeResolution
property of the originalRouteOptions
object.Using the Mapbox Maps SDK for iOS or Mapbox Maps SDK for macOS, you can create an
MGLPolyline
object using these coordinates to display an overview of the route on anMGLMapView
.Declaration
Swift
@objc public let coordinates: [CLLocationCoordinate2D]?
-
The number of coordinates.
The value of this property may be zero or reduced depending on the
routeShapeResolution
property of the originalRouteOptions
object.Note
This initializer is intended for Objective-C usage. In Swift code, use thecoordinates.count
property.Declaration
Swift
@objc open var coordinateCount: UInt { get }
-
Retrieves the coordinates.
The array may be empty or simplified depending on the
routeShapeResolution
property of the originalRouteOptions
object.Using the Mapbox Maps SDK for iOS or Mapbox Maps SDK for macOS, you can create an
MGLPolyline
object using these coordinates to display an overview of the route on anMGLMapView
.Precondition
coordinates
must be large enough to holdcoordinateCount
instances ofCLLocationCoordinate2D
.Note
This initializer is intended for Objective-C usage. In Swift code, use the
coordinates
property.Declaration
Swift
@objc open func getCoordinates(_ coordinates: UnsafeMutablePointer<CLLocationCoordinate2D>)
Parameters
coordinates
A pointer to a C array of
CLLocationCoordinate2D
instances. On output, this array contains all the vertices of the overlay. -
An array of
RouteLeg
objects representing the legs of the route.The number of legs in this array depends on the number of waypoints. A route with two waypoints (the source and destination) has one leg, a route with three waypoints (the source, an intermediate waypoint, and the destination) has two legs, and so on.
To determine the name of the route, concatenate the names of the route’s legs.
Declaration
Swift
@objc public let legs: [RouteLeg]
-
The route’s distance, measured in meters.
The value of this property accounts for the distance that the user must travel to traverse the path of the route. It is the sum of the
distance
properties of the route’s legs, not the sum of the direct distances between the route’s waypoints. You should not assume that the user would travel along this distance at a fixed speed.Declaration
Swift
@objc public let distance: CLLocationDistance
-
The route’s expected travel time, measured in seconds.
The value of this property reflects the time it takes to traverse the entire route. It is the sum of the
expectedTravelTime
properties of the route’s legs. If the route was calculated using theMBDirectionsProfileIdentifierAutomobileAvoidingTraffic
profile, this property reflects current traffic conditions at the time of the request, not necessarily the traffic conditions at the time the user would begin the route. For other profiles, this property reflects travel time under ideal conditions and does not account for traffic congestion. If the route makes use of a ferry or train, the actual travel time may additionally be subject to the schedules of those services.Do not assume that the user would travel along the route at a fixed speed. For more granular travel times, use the
RouteLeg.expectedTravelTime
orRouteStep.expectedTravelTime
. For even more granularity, specify theAttributeOptions.expectedTravelTime
option and use theRouteLeg.expectedSegmentTravelTimes
property.Declaration
Swift
@objc public let expectedTravelTime: TimeInterval
-
RouteOptions
used to create the directions request.The route options object’s profileIdentifier property reflects the primary mode of transportation used for the route. Individual steps along the route might use different modes of transportation as necessary.
Declaration
Swift
@objc public let directionsOptions: DirectionsOptions
-
The access token used to make the directions request.
This property is set automatically if a request is made via
Directions.calculate(_:completionHandler:)
.Declaration
Swift
@objc open var accessToken: String?
-
The endpoint used to make the directions request.
This property is set automatically if a request is made via
Directions.calculate(_:completionHandler:)
.Declaration
Swift
@objc open var apiEndpoint: URL?
-
A unique identifier for a directions request.
Each route produced by a single call to
Directions.calculate(_:completionHandler:)
has the same route identifier.Declaration
Swift
@objc open var routeIdentifier: String?
-
The locale to use for spoken instructions.
This locale is specific to Mapbox Voice API. If
nil
is returned, the instruction should be spoken with an alternative speech synthesizer.Declaration
Swift
@objc open var speechLocale: Locale?
-
The time immediately before a
Directions
object fetched this result.If you manually start fetching a task returned by
Directions.url(forCalculating:)
, this property is set tonil
; use theURLSessionTaskTransactionMetrics.fetchStartDate
property instead. This property may also be set tonil
if you create this result from a JSON object or encoded object.This property does not persist after encoding and decoding.
Declaration
Swift
@objc open var fetchStartDate: Date?
-
The time immediately before a
Directions
object received the last byte of this result.If you manually start fetching a task returned by
Directions.url(forCalculating:)
, this property is set tonil
; use theURLSessionTaskTransactionMetrics.responseEndDate
property instead. This property may also be set tonil
if you create this result from a JSON object or encoded object.This property does not persist after encoding and decoding.
Declaration
Swift
@objc open var responseEndDate: Date?