Leg class

Each element in the legs array specifies a single leg of the journey from the origin to the destination in the calculated route. For routes that contain no waypoints, the route will consist of a single "leg," but for routes that define one or more waypoints, the route will consist of one or more legs, corresponding to the specific legs of the journey.

Each leg within the legs field(s) may contain the following fields:

  • steps contains an array of steps denoting information about each separate step of the leg of the journey. (See Step)

  • distance indicates the total distance covered by this leg, as a field with the following elements:

  • value indicates the distance in meters

  • text contains a human-readable representation of the distance, displayed in units as used at the origin (or as overridden within the units parameter in the request). (For example, miles and feet will be used for any origin within the United States.) Note that regardless of what unit system is displayed as text, the distance.value field always contains a value expressed in meters.

These fields may be absent if the distance is unknown.

  • duration indicates the total duration of this leg, as a field with the following elements:
  • value indicates the duration in seconds.
  • text contains a human-readable representation of the duration.

These fields may be absent if the duration is unknown.

  • durationInTraffic indicates the total duration of this leg. This value is an estimate of the time in traffic based on current and historical traffic conditions. See the trafficModel request parameter for the options you can use to request that the returned value is optimistic, pessimistic, or a best-guess estimate. The duration in traffic is returned only if all of the following are true:

  • The request includes a valid API key, or a valid Google Maps

  • Platform Premium Plan client ID and signature.

  • The request does not include stopover waypoints. If the request includes waypoints, they must be prefixed with via: to avoid stopovers.

  • The request is specifically for driving directions—the mode parameter is set to driving.

  • The request includes a departureTime parameter.

  • Traffic conditions are available for the requested route.

The durationInTraffic contains the following fields:

  • value indicates the duration in seconds.

  • text contains a human-readable representation of the duration.

  • arrivalTime contains the estimated time of arrival for this leg. This property is only returned for transit directions. The result is returned as a Time object with three properties:

  • value the time specified as a DateTime object.

  • text the time specified as a String. The time is displayed in the time zone of the transit stop.

  • timeZone contains the time zone of this station. The value is the name of the time zone as defined in the IANA Time Zone Database, e.g. "America/New_York".

  • departureTime contains the estimated time of departure for this leg, specified as a Time object. The departureTime is only available for transit directions.

  • startLocation contains the latitude/longitude coordinates of the origin of this leg. Because the Directions API calculates directions between locations by using the nearest transportation option (usually a road) at the start and end points, startLocation may be different than the provided origin of this leg if, for example, a road is not near the origin.

  • endLocation contains the latitude/longitude coordinates of the given destination of this leg. Because the Directions API calculates directions between locations by using the nearest transportation option (usually a road) at the start and end points, endLocation may be different than the provided destination of this leg if, for example, a road is not near the destination.

  • startAddress contains the human-readable address (typically a street address) resulting from reverse geocoding the startLocation of this leg.

  • endAddress contains the human-readable address (typically a street address) from reverse geocoding the endLocation of this leg.

Constructors

Leg({Time? arrivalTime, Time? departureTime, Distance? distance, DirectionsDuration? duration, DirectionsDuration? durationInTraffic, String? endAddress, GeoCoord? endLocation, String? startAddress, GeoCoord? startLocation, List<Step>? steps, List<ViaWaypoint>? viaWaypoint})
const
Leg.fromMap(Map<String, dynamic> map)
factory

Properties

arrivalTime Time?
Contains the estimated time of arrival for this leg. This property is only returned for transit directions. The result is returned as a Time object with three properties:
final
departureTime Time?
Contains the estimated time of departure for this leg, specified as a Time object. The departureTime is only available for transit directions.
final
distance Distance?
Indicates the total distance covered by this leg, as a field with the following elements:
final
duration DirectionsDuration?
Indicates the total duration of this leg, as a field with the following elements:
final
durationInTraffic DirectionsDuration?
Indicates the total duration of this leg. This value is an estimate of the time in traffic based on current and historical traffic conditions. See the trafficModel request parameter for the options you can use to request that the returned value is optimistic, pessimistic, or a best-guess estimate. The duration in traffic is returned only if all of the following are true:
final
endAddress String?
Contains the human-readable address (typically a street address) from reverse geocoding the endLocation of this leg.
final
endLocation GeoCoord?
Contains the latitude/longitude coordinates of the given destination of this leg. Because the Directions API calculates directions between locations by using the nearest transportation option (usually a road) at the start and end points, endLocation may be different than the provided destination of this leg if, for example, a road is not near the destination.
final
hashCode int
The hash code for this object.
no setterinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
startAddress String?
Contains the human-readable address (typically a street address) resulting from reverse geocoding the startLocation of this leg.
final
startLocation GeoCoord?
Contains the latitude/longitude coordinates of the origin of this leg. Because the Directions API calculates directions between locations by using the nearest transportation option (usually a road) at the start and end points, startLocation may be different than the provided origin of this leg if, for example, a road is not near the origin.
final
steps List<Step>?
contains an array of steps denoting information about each separate step of the leg of the journey.
final
viaWaypoint List<ViaWaypoint>?
The locations of via waypoints along this leg. contains info about points through which the route was laid
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() String
A string representation of this object.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited