Route
open class Route: NSObject, NSSecureCoding
A Route object defines a single route that the user can follow to visit a series of waypoints in order. The route object includes information about the route, such as its distance and expected travel time. Depending on the criteria used to calculate the route, the route object may also include detailed turn-by-turn instructions.
Typically, you do not create instances of this class directly. Instead, you receive route objects when you request directions using the Directions.calculate(_:completionHandler:) method. However, if you use the Directions.url(forCalculating:) method instead, you can pass the results of the HTTP request into this class’s initializer.
-
Initializes a new route object with the given JSON dictionary representation and waypoints.
This initializer is intended for use in conjunction with the
Directions.url(forCalculating:)method.Declaration
Swift
public convenience init(json: [String: Any], waypoints: [Waypoint], routeOptions: RouteOptions)Parameters
jsonA JSON dictionary representation of the route as returned by the Mapbox Directions API.
waypointsAn array of waypoints that the route visits in chronological order.
routeOptionsThe
RouteOptionsused to create the request.
-
An array of geographic coordinates defining the path of the route from start to finish.
This array may be
nilor simplified depending on therouteShapeResolutionproperty of the originalRouteOptionsobject.Using the Mapbox iOS SDK or Mapbox macOS SDK, you can create an
MGLPolylineobject using these coordinates to display an overview of the route on anMGLMapView.Declaration
Swift
open let coordinates: [CLLocationCoordinate2D]? -
The number of coordinates.
The value of this property may be zero or reduced depending on the
routeShapeResolutionproperty of the originalRouteOptionsobject.Note
This initializer is intended for Objective-C usage. In Swift code, use thecoordinates.countproperty.Declaration
Swift
open var coordinateCount: UInt -
Retrieves the coordinates.
The array may be empty or simplified depending on the
routeShapeResolutionproperty of the originalRouteOptionsobject.Using the Mapbox iOS SDK or Mapbox macOS SDK, you can create an
MGLPolylineobject using these coordinates to display an overview of the route on anMGLMapView.Precondition
coordinatesmust be large enough to holdcoordinateCountinstances ofCLLocationCoordinate2D.Note
This initializer is intended for Objective-C usage. In Swift code, use the
coordinatesproperty.Declaration
Swift
open func getCoordinates(_ coordinates: UnsafeMutablePointer<CLLocationCoordinate2D>)Parameters
coordinatesA pointer to a C array of
CLLocationCoordinate2Dinstances. On output, this array contains all the vertices of the overlay. -
An array of
RouteLegobjects 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
open 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
distanceproperties 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
open 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 under ideal conditions. It is the sum of the
expectedTravelTimeproperties of the route’s legs. You should not assume that the user would travel along the route at a fixed speed. The actual travel time may vary based on the weather, traffic conditions, road construction, and other variables. If the route makes use of a ferry or train, the actual travel time may additionally be subject to the schedules of those services.Declaration
Swift
open let expectedTravelTime: TimeInterval -
RouteOptionsused 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
open let routeOptions: RouteOptions
Install in Dash
Route Class Reference