RouteLeg
open class RouteLeg : Codable, ForeignMemberContainerClass
extension RouteLeg: Equatable
extension RouteLeg: CustomStringConvertible
extension RouteLeg: RouteLegRefreshSource
A RouteLeg object defines a single leg of a route between two waypoints. If the overall route has only two waypoints, it has a single RouteLeg object that covers the entire route. The route leg object includes information about the leg, such as its name, distance, and expected travel time. Depending on the criteria used to calculate the route, the route leg object may also include detailed turn-by-turn instructions.
You do not create instances of this class directly. Instead, you receive route leg objects as part of route objects when you request directions using the Directions.calculate(_:completionHandler:) method.
-
Declaration
Swift
public var foreignMembers: JSONObject -
Foreign attribute arrays associated with this leg.
This library does not officially support any attribute that is documented as a “beta” annotation type in the Mapbox Directions API response format, but you can get and set it as an element of this
JSONObject. It is round-tripped to theannotationproperty in JSON.For non-attribute-related foreign members, use the
foreignMembersproperty.Declaration
Swift
public var attributesForeignMembers: JSONObject
-
Initializes a route leg.
Declaration
Swift
public init(steps: [RouteStep], name: String, distance: Turf.LocationDistance, expectedTravelTime: TimeInterval, typicalTravelTime: TimeInterval? = nil, profileIdentifier: ProfileIdentifier)Parameters
stepsThe steps that are traversed in order.
nameA name that describes the route leg.
expectedTravelTimeThe route leg’s expected travel time, measured in seconds.
typicalTravelTimeThe route leg’s typical travel time, measured in seconds.
profileIdentifierThe primary mode of transportation for the route leg.
-
Creates a route leg from a decoder.
Precondition
If the decoder is decoding JSON data from an API response, theDecoder.userInfodictionary must contain aRouteOptionsorMatchOptionsobject in theCodingUserInfoKey.optionskey. If it does not, aDirectionsCodingError.missingOptionserror is thrown.Declaration
Swift
public required init(from decoder: Decoder) throwsParameters
decoderThe decoder of JSON-formatted API response data or a previously encoded
RouteLegobject. -
Declaration
Swift
public func encode(to encoder: Encoder) throws
-
The starting point of the route leg.
Unless this is the first leg of the route, the source of this leg is the same as the destination of the previous leg.
This property is set to
nilif the leg was decoded from a JSON RouteLeg object.Declaration
Swift
public var source: Waypoint? -
The endpoint of the route leg.
Unless this is the last leg of the route, the destination of this leg is the same as the source of the next leg.
This property is set to
nilif the leg was decoded from a JSON RouteLeg object.Declaration
Swift
public var destination: Waypoint?
-
An array of one or more
RouteStepobjects representing the steps for traversing this leg of the route.Each route step object corresponds to a distinct maneuver and the approach to the next maneuver.
This array is empty if the original
RouteOptionsobject’sRouteOptions.includesStepsproperty is set tofalse.Declaration
Swift
public let steps: [RouteStep] -
The ranges of each step’s segments within the overall leg.
Each range corresponds to an element of the
stepsproperty. Use this property to safely subscript segment-based properties such assegmentCongestionLevelsandsegmentMaximumSpeedLimits.This array is empty if the original
RouteOptionsobject’sRouteOptions.includesStepsproperty is set tofalse.Declaration
Swift
public private(set) lazy var segmentRangesByStep: [Range<Int>] { get set }
-
An array containing the distance (measured in meters) between each coordinate in the route leg geometry.
This property is set if the
RouteOptions.attributeOptionsproperty containsAttributeOptions.distance.Declaration
Swift
open var segmentDistances: [Turf.LocationDistance]? -
An array containing the expected travel time (measured in seconds) between each coordinate in the route leg geometry.
These values are dynamic, accounting for any conditions that may change along a segment, such as traffic congestion if the profile identifier is set to
.automobileAvoidingTraffic.This property is set if the
RouteOptions.attributeOptionsproperty containsAttributeOptions.expectedTravelTime.Declaration
Swift
open var expectedSegmentTravelTimes: [TimeInterval]? -
An array containing the expected average speed (measured in meters per second) between each coordinate in the route leg geometry.
These values are dynamic; rather than speed limits, they account for the road’s classification and/or any traffic congestion (if the profile identifier is set to
.automobileAvoidingTraffic).This property is set if the
RouteOptions.attributeOptionsproperty containsAttributeOptions.speed.Declaration
Swift
open var segmentSpeeds: [LocationSpeed]? -
An array containing the traffic congestion level along each road segment in the route leg geometry.
Traffic data is available in a number of countries and territories worldwide.
You can color-code a route line according to the congestion level along each segment of the route.
This property is set if the
RouteOptions.attributeOptionsproperty containsAttributeOptions.congestionLevel.Declaration
Swift
open var segmentCongestionLevels: [CongestionLevel]? -
An array containing the traffic congestion level along each road segment in the route leg geometry in numeric form.
Entries may be
nilif congestion on that segment is not known.Traffic data is available in a number of countries and territories worldwide.
You can color-code a route line according to the congestion level along each segment of the route.
This property is set if the
RouteOptions.attributeOptionsproperty containsAttributeOptions.numericCongestionLevel.Declaration
Swift
open var segmentNumericCongestionLevels: [NumericCongestionLevel?]? -
An array containing the maximum speed limit along each road segment along the route leg’s shape.
The maximum speed may be an advisory speed limit for segments where legal limits are not posted, such as highway entrance and exit ramps. If the speed limit along a particular segment is unknown, it is represented in the array by a measurement whose value is negative. If the speed is unregulated along the segment, such as on the German Autobahn system, it is represented by a measurement whose value is
Double.infinity.Speed limit data is available in a number of countries and territories worldwide.
This property is set if the
RouteOptions.attributeOptionsproperty containsAttributeOptions.maximumSpeedLimit.Declaration
Swift
open var segmentMaximumSpeedLimits: [Measurement<UnitSpeed>?]? -
An array of
Closureobjects describing live-traffic related closures that occur along the route.This information is only available for the
mapbox/driving-trafficprofile and whenRouteOptions.attributeOptionsproperty containsAttributeOptions.closures.Declaration
Swift
open var closures: [Closure]? -
Returns the ISO 3166-1 alpha-2 region code for the administrative region through which the given intersection passes. The intersection is identified by its step index and intersection index.
Seealso
Intersection.regionCodeDeclaration
Swift
public func regionCode(atStepIndex stepIndex: Int, intersectionIndex: Int) -> String?
-
A name that describes the route leg.
The name describes the leg using the most significant roads or trails along the route leg. You can display this string to the user to help the user can distinguish one route from another based on how the legs of the routes are named.
The leg’s name does not identify the start and end points of the leg. To distinguish one leg from another within the same route, concatenate the
nameproperties of thesourceanddestinationwaypoints.Declaration
Swift
public let name: String -
The route leg’s distance, measured in meters.
The value of this property accounts for the distance that the user must travel to arrive at the destination from the source. It is not the direct distance between the source and destination, nor should not assume that the user would travel along this distance at a fixed speed.
Declaration
Swift
public let distance: Turf.LocationDistance -
The route leg’s expected travel time, measured in seconds.
The value of this property reflects the time it takes to traverse the route leg. If the route was calculated using the
ProfileIdentifier.automobileAvoidingTrafficprofile, this property reflects current traffic conditions at the time of the request, not necessarily the traffic conditions at the time the user would begin this leg. For other profiles, this property reflects travel time under ideal conditions and does not account for traffic congestion. If the leg 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 leg at a fixed speed. For the expected travel time on each individual segment along the leg, use the
RouteStep.expectedTravelTimesproperty. For more granularity, specify theAttributeOptions.expectedTravelTimeoption and use theexpectedSegmentTravelTimesproperty.Declaration
Swift
open var expectedTravelTime: TimeInterval -
The administrative regions through which the leg passes.
Items are ordered by appearance, most recent one is at the beginning. This property is set to
nilif no administrative region data is available. You can alse refer toIncident.regionCodeto get corresponding region string code.Declaration
Swift
open var administrativeRegions: [AdministrativeRegion]? -
Describes where a particular
Waypointpassed toRouteOptionsmatches to the route along aRouteLeg.The property is non-nil when for one or several
Waypointobjects passed toRouteOptionshaveseparatesLegsproperty set tofalse.Declaration
Swift
open var viaWaypoints: [SilentWaypoint]? -
The route leg’s typical travel time, measured in seconds.
The value of this property reflects the typical time it takes to traverse the route leg. This property is available when using the
ProfileIdentifier.automobileAvoidingTrafficprofile. This property reflects typical traffic conditions at the time of the request, not necessarily the typical traffic conditions at the time the user would begin this leg. If the leg makes use of a ferry, the typical travel time may additionally be subject to the schedule of this service.Do not assume that the user would travel along the route at a fixed speed. For more granular typical travel times, use the
RouteStep.typicalTravelTimeproperty.Declaration
Swift
open var typicalTravelTime: TimeInterval?
-
The primary mode of transportation for the route leg.
The value of this property depends on the
RouteOptions.profileIdentifierproperty of the originalRouteOptionsobject. This property reflects the primary mode of transportation used for the route leg. Individual steps along the route leg might use different modes of transportation as necessary.Declaration
Swift
public let profileIdentifier: ProfileIdentifier -
Declaration
Swift
public static func == (lhs: RouteLeg, rhs: RouteLeg) -> Bool -
Declaration
Swift
public var description: String { get } -
Live-traffic related closure that occured along the route.
See moreDeclaration
Swift
public struct Closure : Codable, Equatable, ForeignMemberContainer
Install in Dash
RouteLeg Class Reference