RouteLeg

open class RouteLeg: NSObject, NSSecureCoding

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.

  • Initializes a new route leg object with the given JSON dictionary representation and waypoints.

    Normally, 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.calculateDirections(options:completionHandler:) method.

    Declaration

    Swift

    public convenience init(json: [String: Any], source: Waypoint, destination: Waypoint, profileIdentifier: MBDirectionsProfileIdentifier)

    Parameters

    json

    A JSON dictionary representation of a route leg object as returnd by the Mapbox Directions API.

    source

    The waypoint at the beginning of the leg.

    destination

    The waypoint at the end of the leg.

    profileIdentifier

    The profile identifier used to request the routes.

  • 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 name properties of the source and destination waypoints.

    Declaration

    Swift

    open 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

    open let distance: CLLocationDistance
  • 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 MBDirectionsProfileIdentifierAutomobileAvoidingTraffic 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 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.expectedTravelTimes property. For more granularity, specify the AttributeOptions.expectedTravelTime option and use the expectedSegmentTravelTimes property.

    Declaration

    Swift

    open let expectedTravelTime: TimeInterval
  • A string specifying the primary mode of transportation for the route leg.

    The value of this property is MBDirectionsProfileIdentifierAutomobile, MBDirectionsProfileIdentifierAutomobileAvoidingTraffic, MBDirectionsProfileIdentifierCycling, or MBDirectionsProfileIdentifierWalking, depending on the profileIdentifier property of the original RouteOptions object. 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

    open let profileIdentifier: MBDirectionsProfileIdentifier