Route

open class Route : DirectionsResult
extension Route: Equatable

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:) or Directions.calculateRoutes(matching:completionHandler:) method. However, if you use the Directions.url(forCalculating:) method instead, you can use JSONDecoder to convert the HTTP response into a RouteResponse or MapMatchingResponse object and access the RouteResponse.routes or MapMatchingResponse.routes property.

  • Initializes a route.

    Declaration

    Swift

    public override init(legs: [RouteLeg], shape: LineString?, distance: CLLocationDistance, expectedTravelTime: TimeInterval)

    Parameters

    legs

    The legs that are traversed in order.

    shape

    The roads or paths taken as a contiguous polyline.

    distance

    The route’s distance, measured in meters.

    expectedTravelTime

    The route’s expected travel time, measured in seconds.

  • Initializes a route from a decoder.

    Precondition

    If the decoder is decoding JSON data from an API response, the Decoder.userInfo dictionary must contain a RouteOptions or MatchOptions object in the CodingUserInfoKey.options key. If it does not, a DirectionsCodingError.missingOptions error is thrown.

    Declaration

    Swift

    public required init(from decoder: Decoder) throws

    Parameters

    decoder

    The decoder of JSON-formatted API response data or a previously encoded Route object.

  • Declaration

    Swift

    public static func == (lhs: Route, rhs: Route) -> Bool
  • Merges the attributes of the given route’s legs into the receiver’s legs.

    Declaration

    Swift

    public func refreshLegAttributes(from refreshedRoute: RefreshedRoute)

    Parameters

    refreshedRoute

    The route containing leg attributes to merge into the receiver. If this route contains fewer legs than the receiver, this method skips legs from the beginning of the route to make up the difference, so that merging the attributes from a one-leg route affects only the last leg of the receiver.