This product is in Legacy status. As of October 2026, Directions API (Legacy) can no longer be enabled for new Google Cloud projects. Existing projects remain fully supported. For new features and improved performance, migrate to the Routes API.
Sample responses
Directions responses are returned in the format indicated by the
output flag within the URL request path.
A sample HTTP request is shown below, calculating the route from Chicago, IL to Los Angeles, CA via two waypoints in Joplin, MO and Oklahoma City, OK.
URL
https://maps.googleapis.com/maps/api/directions/json ?destination=Los%20Angeles%2C%20CA &origin=Chicago%2C%20IL &waypoints=Joplin%2C%20MO%7COklahoma%20City%2C%20OK &key=YOUR_API_KEY
curl
curl -L -X GET 'https://maps.googleapis.com/maps/api/directions/json?origin=Chicago%2C%20IL&destination=Los%20Angeles%2C%20CA&waypoints=Joplin%2C%20MO%7COklahoma%20City%2C%20OK&key=YOUR_API_KEY'
The above example requests JSON output. It's also possible to request XML output. Select the tabs below to see the sample JSON and XML responses.
JSON
{ "geocoded_waypoints": [ { "geocoder_status": "OK", "place_id": "ChIJ7cv00DwsDogRAMDACa2m4K8", "types": ["locality", "political"], }, { "geocoder_status": "OK", "place_id": "ChIJ69Pk6jdlyIcRDqM1KDY3Fpg", "types": ["locality", "political"], }, { "geocoder_status": "OK", "place_id": "ChIJgdL4flSKrYcRnTpP0XQSojM", "types": ["locality", "political"], }, { "geocoder_status": "OK", "place_id": "ChIJE9on3F3HwoAR9AhGJW_fL-I", "types": ["locality", "political"], }, ], "routes": [ { "bounds": { "northeast": { "lat": 41.8781139, "lng": -87.6297872 }, "southwest": { "lat": 34.0523525, "lng": -118.2435717 }, }, "copyrights": "Map data ©2022 Google, INEGI", "legs": [ { "distance": { "text": "579 mi", "value": 932311 }, "duration": { "text": "8 hours 48 mins", "value": 31653 }, "end_address": "Joplin, MO, USA", "end_location": { "lat": 37.0842449, "lng": -94.513284 }, "start_address": "Chicago, IL, USA", "start_location": { "lat": 41.8781139, "lng": -87.6297872 }, "steps": [ { "distance": { "text": "443 ft", "value": 135 }, "duration": { "text": "1 min", "value": 24 }, "end_location": { "lat": 41.8769003, "lng": -87.6297353 }, "html_instructions": "Head <b>south</b> on <b>S Federal St</b> toward <b>W Van Buren St</b>", "polyline": { "points": "eir~FdezuOdCEjBC" }, "start_location": { "lat": 41.8781139, "lng": -87.6297872 }, "travel_mode": "DRIVING", }, { "distance": { "text": "269 ft", "value": 82 }, "duration": { "text": "1 min", "value": 20 }, "end_location": { "lat": 41.8768866, "lng": -87.63073 }, "html_instructions": "Turn <b>right</b> at the 1st cross street onto <b>W Van Buren St</b>", "maneuver": "turn-right", "polyline": { "points": "sar~FzdzuO@fC?|@" }, "start_location": { "lat": 41.8769003, "lng": -87.6297353 }, "travel_mode": "DRIVING", }, // Additional steps omitted for brevity ], "traffic_speed_entry": [], "via_waypoint": [], }, // Additional legs (Joplin to Oklahoma City, Oklahoma City to Los Angeles) omitted for brevity ], "overview_polyline": { "points": "eir~FdezuOxyFzfFl`G|qZvtSzqo@d}EhlLtqIdjFhrTfvEdca@... (truncated for brevity)", }, "summary": "I-55 S and I-44", "warnings": [], "waypoint_order": [0, 1], }, ], "status": "OK", }
XML
<DirectionsResponse> <status>OK</status> <route> <summary>I-55 S and I-44</summary> <leg> <step> <travel_mode>DRIVING</travel_mode> <start_location> <lat>41.8781139</lat> <lng>-87.6297872</lng> </start_location> <end_location> <lat>41.8769003</lat> <lng>-87.6297353</lng> </end_location> <polyline> <points>eir~FdezuOdCEjBC</points> </polyline> <duration> <value>24</value> <text>1 min</text> </duration> <html_instructions>Head <b>south</b> on <b>S Federal St</b> toward <b>W Van Buren St</b></html_instructions> <distance> <value>135</value> <text>443 ft</text> </distance> </step> <step> <travel_mode>DRIVING</travel_mode> <start_location> <lat>41.8769003</lat> <lng>-87.6297353</lng> </start_location> <end_location> <lat>41.8768866</lat> <lng>-87.6307300</lng> </end_location> <polyline> <points>sar~FzdzuO@fC?|@</points> </polyline> <duration> <value>20</value> <text>1 min</text> </duration> <html_instructions>Turn <b>right</b> at the 1st cross street onto <b>W Van Buren St</b></html_instructions> <distance> <value>82</value> <text>269 ft</text> </distance> <maneuver>turn-right</maneuver> </step> <!-- Additional steps omitted for brevity --> <duration> <value>31653</value> <text>8 hours 48 mins</text> </duration> <distance> <value>932311</value> <text>579 mi</text> </distance> <start_location> <lat>41.8781139</lat> <lng>-87.6297872</lng> </start_location> <end_location> <lat>37.0842449</lat> <lng>-94.5132840</lng> </end_location> <start_address>Chicago, IL, USA</start_address> <end_address>Joplin, MO, USA</end_address> </leg> <!-- Additional legs (Joplin to Oklahoma City, Oklahoma City to Los Angeles) omitted for brevity --> <copyrights>Map data ©2022 Google, INEGI</copyrights> <overview_polyline> <points>eir~FdezuOxyFzfFl`G|qZvtSzqo@d}EhlLtqIdjFhrTfvEdca@... (truncated for brevity)</points> </overview_polyline> <waypoint_index>0</waypoint_index> <waypoint_index>1</waypoint_index> <bounds> <southwest> <lat>34.0523525</lat> <lng>-118.2435717</lng> </southwest> <northeast> <lat>41.8781139</lat> <lng>-87.6297872</lng> </northeast> </bounds> </route> <geocoded_waypoint> <geocoder_status>OK</geocoder_status> <type>locality</type> <type>political</type> <place_id>ChIJ7cv00DwsDogRAMDACa2m4K8</place_id> </geocoded_waypoint> <geocoded_waypoint> <geocoder_status>OK</geocoder_status> <type>locality</type> <type>political</type> <place_id>ChIJ69Pk6jdlyIcRDqM1KDY3Fpg</place_id> </geocoded_waypoint> <geocoded_waypoint> <geocoder_status>OK</geocoder_status> <type>locality</type> <type>political</type> <place_id>ChIJgdL4flSKrYcRnTpP0XQSojM</place_id> </geocoded_waypoint> <geocoded_waypoint> <geocoder_status>OK</geocoder_status> <type>locality</type> <type>political</type> <place_id>ChIJE9on3F3HwoAR9AhGJW_fL-I</place_id> </geocoded_waypoint> </DirectionsResponse>
The remainder of this documentation will use JSON syntax. In most cases, the output format does not matter for purposes of illustrating concepts or field names in the documentation. However, note the following subtle differences:
- XML results are wrapped in a root
<DirectionsResponse>element. - JSON denotes entries with multiple elements by plural arrays (such as
stepsandlegs), while XML denotes these using multiple singular elements (such as<step>and<leg>). - JSON denotes waypoint order via the
waypoint_orderfield, while XML denotes these using individual<waypoint_index>elements. - Blank elements are indicated through empty arrays in JSON, but by the absence of any
such element in XML. A response that generates no results will return an empty
routesarray in JSON, but no<route>elements in XML, for example.
DirectionsResponse
| Field | Required | Type | Description |
|---|---|---|---|
|
required | Array<DirectionsRoute> |
Contains an array of routes from the origin to the destination. Routes consist of nested Legs and Steps. See DirectionsRoute for more information. |
|
required | DirectionsStatus |
Contains the status of the request, and may contain debugging information to help you track down why the request failed. See DirectionsStatus for more information. |
|
optional | Array<TravelMode> |
Contains an array of available travel modes. This field is returned when a request specifies a travel mode and gets no results. The array contains the available travel modes in the countries of the given set of waypoints. This field is not returned if one or more of the waypoints are 'via waypoints'. See TravelMode for more information. |
|
optional | string |
When the service returns a status code other than |
|
optional | Array<DirectionsGeocodedWaypoint> |
Contains an array with details about the geocoding of origin, destination and waypoints. Elements in the geocoded_waypoints array correspond, by their zero-based position, to the origin, the waypoints in the order they are specified, and the destination. These details won't be present for waypoints specified as textual latitude/longitude values if the service returns no results. This is because such waypoints are only reverse geocoded to obtain their representative address after a route has been found. An empty JSON object will occupy the corresponding places in the geocoded_waypoints array. See DirectionsGeocodedWaypoint for more information. |
DirectionsRoute
Routes consist of nested legs and steps.
| Field | Required | Type | Description |
|---|---|---|---|
|
required | Bounds |
Contains the viewport bounding box of the
See Bounds for more information. |
|
required | string |
Contains the copyright notices to be displayed for this route. You must handle and display this information yourself. This content is meant to be read as-is. Don't programmatically parse this display-only content. |
|
required | Array<DirectionsLeg> |
An array which contains information about a leg of the route, between two locations within the given route. A separate leg will be present for each waypoint or destination specified. (A route with no waypoints will contain exactly one leg within the legs array.) Each leg consists of a series of steps. See DirectionsLeg for more information. |
|
required | DirectionsPolyline |
Contains an object that holds an encoded polyline representation of the route. This polyline is an approximate (smoothed) path of the resulting directions. See DirectionsPolyline for more information. |
|
required | string |
Contains a short textual description for the route, suitable for naming and disambiguating the route from alternatives. |
|
required | Array<string> |
Contains an array of warnings to be displayed when showing these directions. You must handle and display these warnings yourself. |
|
required | Array<integer> |
An array indicating the order of any waypoints in the calculated route. This waypoints may be reordered if the request was passed optimize:true within its waypoints parameter. |
|
optional | Fare |
If present, contains the total fare (that is, the total ticket costs) on this route. This property is only returned for transit requests and only for routes where fare information is available for all transit legs. See Fare for more information. |
Bounds
A rectangle in geographical coordinates from points at the southwest and northeast corners.
| Field | Required | Type | Description |
|---|---|---|---|
|
required | LatLngLiteral | See LatLngLiteral for more information. |
|
required | LatLngLiteral | See LatLngLiteral for more information. |
LatLngLiteral
An object describing a specific location with Latitude and Longitude in decimal degrees.
| Field | Required | Type | Description |
|---|---|---|---|
|
required | number |
Latitude in decimal degrees |
|
required | number |
Longitude in decimal degrees |
DirectionsLeg
| Field | Required | Type | Description |
|---|---|---|---|
|
required | string |
Contains the human-readable address (typically a street address) from reverse geocoding
the |
|
required | LatLngLiteral |
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,
See LatLngLiteral for more information. |
|
required | string |
Contains the human-readable address (typically a street address) resulting from reverse
geocoding the |
|
required | LatLngLiteral |
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, See LatLngLiteral for more information. |
|
required | Array<DirectionsStep> |
An array of steps denoting information about each separate step of the leg of the journey. See DirectionsStep for more information. |
|
optional | Array<DirectionsTrafficSpeedEntry> |
Information about traffic speed along the leg. See DirectionsTrafficSpeedEntry for more information. |
|
required | Array<DirectionsViaWaypoint> |
The locations of via waypoints along this leg. See DirectionsViaWaypoint for more information. |
|
optional | TimeZoneTextValueObject |
Contains the estimated time of arrival for this leg. This property is only returned for transit directions. See TimeZoneTextValueObject for more information. |
|
optional | TimeZoneTextValueObject |
Contains the estimated time of departure for this leg, specified as a Time object. The
See TimeZoneTextValueObject for more information. |
|
optional | TextValueObject |
The total distance covered by this leg. See TextValueObject for more information. |
|
optional | TextValueObject |
The total duration of this leg. See TextValueObject for more information. |
|
optional | TextValueObject |
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
See TextValueObject for more information. |
DirectionsStep
Each element in the steps array defines a single step of the calculated directions. A step is the most atomic unit of a direction's route, containing a single step describing a specific, single instruction on the journey. E.g. "Turn left at W. 4th St." The step not only describes the instruction but also contains distance and duration information relating to how this step relates to the following step. For example, a step denoted as "Merge onto I-80 West" may contain a duration of "37 miles" and "40 minutes," indicating that the next step is 37 miles/40 minutes from this step.
When using the Directions API to search for transit directions, the steps array will include additional transit details in the form of a transit_details array. If the directions include multiple modes of transportation, detailed directions will be provided for walking or driving steps in an inner steps array. For example, a walking step will include directions from the start and end locations: "Walk to Innes Ave & Fitch St". That step will include detailed walking directions for that route in the inner steps array, such as: "Head north-west", "Turn left onto Arelious Walker", and "Turn left onto Innes Ave".
| Field | Required | Type | Description |
|---|---|---|---|
|
required | TextValueObject |
Contains the typical time required to perform the step, until the next step. This field may be undefined if the duration is unknown. See TextValueObject for more information. |
|
required | LatLngLiteral |
Contains the location of the last point of this step. See LatLngLiteral for more information. |
|
required | string |
Contains formatted instructions for this step, presented as an HTML text string. This content is meant to be read as-is. Don't programmatically parse this display-only content. |
|
required | DirectionsPolyline |
Contains a single points object that holds an encoded polyline representation of the step. This polyline is an approximate (smoothed) path of the step. See DirectionsPolyline for more information. |
|
required | LatLngLiteral |
Contains the location of the starting point of this step. See LatLngLiteral for more information. |
|
required | TravelMode |
Contains the type of travel mode used. See TravelMode for more information. |
|
optional | TextValueObject |
Contains the distance covered by this step until the next step. This field may be undefined if the distance is unknown. See TextValueObject for more information. |
|
optional | string |
Contains the action to take for the current step (turn left, merge, straight, etc.). Values are subject to change, and new values may be introduced without prior notice.
The allowed values include:
turn-slight-left, turn-sharp-left,
turn-left, turn-slight-right, turn-sharp-right,
keep-right, keep-left, uturn-left,
uturn-right, turn-right, straight,
ramp-left, ramp-right, merge,
fork-left, fork-right, ferry,
ferry-train, roundabout-left, and
roundabout-right
|
|
optional |
Contains detailed directions for walking or driving steps in transit directions. Substeps are only available when travel_mode is set to "transit". The inner steps array is of the same type as steps. |
|
|
optional | DirectionsTransitDetails |
Details pertaining to this step if the travel mode is
See DirectionsTransitDetails for more information. |
TextValueObject
An object containing a numeric value and its formatted text representation.
| Field | Required | Type | Description |
|---|---|---|---|
|
required | string |
String value. |
|
required | number |
Numeric value. |
DirectionsPolyline
Polyline encoding is a lossy compression algorithm that lets you store a series of coordinates as a single string. Point coordinates are encoded using signed values. If you only have a few static points, you may also want to use the interactive polyline encoding utility.
The encoding process converts a binary value into a series of character codes for ASCII characters using the familiar base64 encoding scheme: to ensure proper display of these characters, encoded values are summed with 63 (the ASCII character '?') before converting them into ASCII. The algorithm also checks for additional character codes for a given point by checking the least significant bit of each byte group; if this bit is set to 1, the point is not yet fully formed and additional data must follow.
Additionally, to conserve space, points only include the offset from the previous point (except of course for the first point). All points are encoded in Base64 as signed integers, as latitudes and longitudes are signed values. The encoding format within a polyline needs to represent two coordinates representing latitude and longitude to a reasonable precision. Given a maximum longitude of +/- 180 degrees to a precision of 5 decimal places (180.00000 to -180.00000), this results in the need for a 32 bit signed binary integer value.
| Field | Required | Type | Description |
|---|---|---|---|
|
required | string |
A single string representation of the polyline. |
TravelMode
DRIVING(default) indicates calculation using the road network.-
BICYCLINGrequests calculation for bicycling using bicycle paths & preferred streets (where available). TRANSITrequests calculation using public transit routes (where available).-
WALKINGrequests calculation for walking using pedestrian paths & sidewalks (where available).
DirectionsTransitDetails
Additional information that is not relevant for other modes of transportation.
| Field | Required | Type | Description |
|---|---|---|---|
|
optional | DirectionsTransitStop |
The arrival transit stop. See DirectionsTransitStop for more information. |
|
optional | TimeZoneTextValueObject | See TimeZoneTextValueObject for more information. |
|
optional | DirectionsTransitStop |
The departure transit stop. See DirectionsTransitStop for more information. |
|
optional | TimeZoneTextValueObject | See TimeZoneTextValueObject for more information. |
|
optional | string |
Specifies the direction in which to travel on this line, as it is marked on the vehicle or at the departure stop. This will often be the terminus station. |
|
optional | integer |
Specifies the expected number of seconds between departures from the same stop at this
time. For example, with a
|
|
optional | DirectionsTransitLine |
Contains information about the transit line used in this step. See DirectionsTransitLine for more information. |
|
optional | integer |
The number of stops from the departure to the arrival stop. This includes the arrival
stop, but not the departure stop. For example, if your directions involve leaving from
Stop A, passing through stops B and C, and arriving at stop D,
|
|
optional | string |
The text that appears in schedules and sign boards to identify a transit trip to
passengers. The text should uniquely identify a trip within a service day. For example,
"538" is the
|
DirectionsTransitStop
| Field | Required | Type | Description |
|---|---|---|---|
|
required | LatLngLiteral |
The location of the stop. See LatLngLiteral for more information. |
|
required | string |
The name of the transit stop. |
TimeZoneTextValueObject
An object containing Unix epoch time, a time zone, and its formatted text representation.
| Field | Required | Type | Description |
|---|---|---|---|
|
required | string |
The time specified as a string in the time zone. |
|
required | string |
Contains the time zone. The value is the name of the time zone as defined in the IANA Time Zone Database, e.g. "America/New_York". |
|
required | number |
The time specified as Unix epoch time, or seconds since midnight, January 1, 1970 UTC. |
DirectionsTransitLine
| Field | Required | Type | Description |
|---|---|---|---|
|
required | Array<DirectionsTransitAgency> |
The transit agency (or agencies) that operates this transit line. See DirectionsTransitAgency for more information. |
|
required | string |
The full name of this transit line, e.g. "8 Avenue Local". |
|
optional | string |
The color commonly used in signage for this line. |
|
optional | string |
Contains the URL for the icon associated with this line. |
|
optional | string |
The short name of this transit line. This will normally be a line number, such as "M7" or "355". |
|
optional | string |
The color commonly used in signage for this line. |
|
optional | string |
Contains the URL for this transit line as provided by the transit agency. |
|
optional | DirectionsTransitVehicle |
The type of vehicle that operates on this transit line. See DirectionsTransitVehicle for more information. |
DirectionsTransitAgency
| Field | Required | Type | Description |
|---|---|---|---|
|
optional | string |
The name of this transit agency. |
|
optional | string |
The transit agency's phone number. |
|
optional | string |
The transit agency's URL. |
DirectionsTransitVehicle
| Field | Required | Type | Description |
|---|---|---|---|
|
required | string |
The name of this vehicle, capitalized. |
|
required | string |
The type of vehicle used.
The allowed values include:
BUS, CABLE_CAR,
COMMUTER_TRAIN, FERRY, FUNICULAR,
GONDOLA_LIFT, HEAVY_RAIL, HIGH_SPEED_TRAIN,
INTERCITY_BUS, LONG_DISTANCE_TRAIN, METRO_RAIL,
MONORAIL, OTHER, RAIL, SHARE_TAXI,
SUBWAY, TRAM, and
TROLLEYBUS
|
|
optional | string |
Contains the URL for an icon associated with this vehicle type. |
|
optional | string |
Contains the URL for the icon associated with this vehicle type, based on the local transport signage. |
DirectionsTrafficSpeedEntry
| Field | Required | Type | Description |
|---|---|---|---|
|
required | number |
The offset along the path (in meters) up to which this speed category is valid. |
|
required | string |
The current traffic/speed conditions on this portion of a path. |
DirectionsViaWaypoint
| Field | Required | Type | Description |
|---|---|---|---|
|
optional | LatLngLiteral |
The location of the waypoint. See LatLngLiteral for more information. |
|
optional | integer |
The index of the step containing the waypoint. |
|
optional | number |
The position of the waypoint along the step's polyline, expressed as a ratio from 0 to 1. |
Fare
The total fare for the route.
{
"currency" : "USD",
"value" : 6,
"text" : "$6.00"
}
| Field | Required | Type | Description |
|---|---|---|---|
|
required | string |
An ISO 4217 currency code indicating the currency that the amount is expressed in. |
|
required | string |
The total fare amount, formatted in the requested language. |
|
required | number |
The total fare amount, in the currency specified. |
DirectionsStatus
The status field within the Directions response object contains the status of the request, and may contain debugging information to help you track down why the Directions service failed. The status field may contain the following values:
OKindicates the response contains a valid result.-
NOT_FOUNDindicates at least one of the locations specified in the request's origin, destination, or waypoints couldn't be geocoded. -
ZERO_RESULTSindicates no route could be found between the origin and destination. -
MAX_WAYPOINTS_EXCEEDEDindicates that too many waypoints were provided in the request. For applications using the Directions API as a web service, or the directions service in the Maps JavaScript API, the maximum allowed number of waypoints is 25, plus the origin and destination. -
MAX_ROUTE_LENGTH_EXCEEDEDindicates the requested route is too long and cannot be processed. This error occurs when more complex directions are returned. Try reducing the number of waypoints, turns, or instructions. -
INVALID_REQUESTindicates that the provided request was invalid. Common causes of this status include an invalid parameter or parameter value. -
OVER_DAILY_LIMITindicates any of the following:- The API key is missing or invalid.
- Billing has not been enabled on your account.
- A self-imposed usage cap has been exceeded.
- The provided method of payment is no longer valid (for example, a credit card has expired).
-
OVER_QUERY_LIMITindicates the service has received too many requests from your application within the allowed time period. -
REQUEST_DENIEDindicates that the service denied use of the directions service by your application. -
UNKNOWN_ERRORindicates a directions request couldn't be processed due to a server error. The request may succeed if you try again.
DirectionsGeocodedWaypoint
| Field | Required | Type | Description |
|---|---|---|---|
|
optional | string |
Indicates the status code resulting from the geocoding operation. This field may contain the following values.
The allowed values include:
OK, and
ZERO_RESULTS
|
|
optional |
Indicates that the geocoder did not return an exact match for the original request, though it was able to match part of the requested address. You may want to examine the original request for misspellings and/or an incomplete address. Partial matches most often occur for street addresses that don't exist within the locality you pass in the request. Partial matches may also be returned when a request matches two or more locations in the same locality. For example, "21 Henr St, Bristol, UK" will return a partial match for both Henry Street and Henrietta Street. Note that if a request includes a misspelled address component, the geocoding service may suggest an alternative address. Suggestions triggered in this way will also be marked as a partial match. |
|
|
optional | string |
A unique identifier that can be used with other Google APIs. See the Place ID overview. |
|
optional | Array<string> |
Indicates the address type of the geocoding result used for calculating directions.
An empty list of types indicates there are no known types for the particular address component, for example, Lieu-dit in France. |