**European Economic Area (EEA) developers**

> [!NOTE]
> If your billing address is in the European Economic Area, effective on 8 July 2025, the [Google Maps Platform EEA Terms of Service](https://cloud.google.com/terms/maps-platform/eea) will apply to your use of the Services. Functionality varies by region. [Learn more](https://developers.google.com/maps/comms/eea/faq.md.txt).

A transit route provides navigation instructions using the public transportation
options available in the region. Transit options may include buses, subways, and
trains, among others. A transit route also usually includes instructions on
walking to, from, and between transit stations. Because a transit route
typically requires you to travel using more than one mode of travel, how you
request the route and some parts of the response are different.

> [!NOTE]
> **Note:** You can also get a route matrix on transit. For an example, see [Get a route matrix on transit](https://developers.google.com/maps/documentation/routes/transit-rm.md.txt).

## How transit routes differ from other routes

Transit routes, which you request by setting a travelMode of TRANSIT, differ
from routes using different travelMode options.
You cannot request all of the same objects and options, and the response returns
different fields, when compared to other routes.

In the Routes API, steps are consistently one navigation instruction
across all types of travel. So each navigation instruction is a step. A transit
route response is very similar to routes with other travel modes, with a few key
differences:

| Request differences | Response differences |
|---|---|
| You cannot specify intermediate waypoints. | Includes Transit details. |
| Cannot get eco-friendly routes | Includes metadata for each travel mode that contains the summary of the steps for that travel mode, in the \`stepsOverview\` (to request this metadata, use the \`routes.legs.stepsOverview\` field mask). |
| Cannot specify how and if to include traffic data |   |
| Cannot specify route features to avoid |   |
| Can only specify `transitPreferences` for `routingPreference`. For details, see [`TransitPreferences`](https://developers.google.com/maps/documentation/routes/reference/rest/v2/TransitPreferences.md.txt). |   |

For more information about the response returned by the Routes API, see
[Review transit route responses](https://developers.google.com/maps/documentation/routes/transit-route.md.txt#transit-route-example).

## To get a transit route

1. Set your origin and destination.

   > [!NOTE]
   > **Note:** Transit routes don't support intermediate waypoints.

2. Set the travel mode to transit:

   `travelMode: "TRANSIT"`
3. Add a field mask to get the response fields you want. See
   [Request the transit route fields you need](https://developers.google.com/maps/documentation/routes/transit-route.md.txt#transit-fields).

4. If needed, set optional parameters. See
   [Set parameters for a transit route](https://developers.google.com/maps/documentation/routes/transit-route.md.txt#options).

### Request the transit route fields you need

Request the transit route fields you need using field masks. The following table
contains some suggested responses for a transit
route, and the field mask to use to request them.

| To request this information | Use this field mask |
|---|---|
| All route details | `routes.*` |
| All transit details | `routes.legs.steps.transitDetails` |
| Start location for each leg | `routes.legs.steps.startLocation` |
| End location for each leg | `routes.legs.steps.endLocation` |
| Route polyline for each step | `routes.legs.steps.polyline` |
| Type of transit used for each step | `routes.legs.steps.travelMode` |
| Estimated fare for each step and the route, and Localized estimated fare | `routes.travel_advisory.transitFare localized routes.localizedValues.transitFare` Note: `transitFare` is only provided if the API can determine transit fare information for all steps. |
| Localized text for duration and distance | `routes.localizedValues` |

For more information about setting field masks, see
[Choose fields to return](https://developers.google.com/maps/documentation/routes/choose_fields.md.txt).

### Set parameters for a transit route

Here are the relevant parameters for transit routes:

| To do this | Use this parameter | Notes |
|---|---|---|
| Select transit mode | `travelMode: "TRANSIT"` | Required. [Learn more](https://developers.google.com/maps/documentation/routes/reference/rest/v2/RouteTravelMode.md.txt). |
| Set an arrival or departure time | `"arrivalTime": "yyyy-mm-ddThh:mm:ssZ"` OR `"departureTime": "yyyy-mm-ddThh:mm:ssZ"` | Optional. You can specify either arrival_time or departure_time. If neither time is specified, the `departure_time` defaults to the current execution time (`now`). You can set arrival and departure times only within the following time window, with the current execution time (`now`) as the reference: - up to and including 7 days prior to `now` - up to and including 100 days after `now` Time is expressed as a timestamp in RFC3339 UTC "Zulu" format. [Learn more](https://developers.google.com/maps/documentation/routes/reference/rest/v2/TopLevel/computeRoutes.md.txt#request-body) Note: Transit schedules change frequently, available transit trips may change over time and there is no guarantee to provide consistent results for predictions far in advance. |
| Include alternate routes | `"computeAlternativeRoutes": true` | Optional. Set to true to have Compute Routes compute up to 3 additional routes, when available. [Learn more](https://developers.google.com/maps/documentation/routes/reference/rest/v2/TopLevel/computeRoutes.md.txt#request-body) |
| Specify preferences for the transit type | `"transitPreferences": { allowedTravelModes: ["BUS","SUBWAY","TRAIN","LIGHT_RAIL","RAIL"]}` Note: If you specify a preferred travel mode, returned routes may still use other transit modes, even only use other transit modes, depending on the efficiency of the route on, and the availability of, the preferred travel. | Optional. Specify preferred transit travel modes. [Learn more](https://developers.google.com/maps/documentation/routes/reference/rest/v2/TransitPreferences.md.txt) |
| Specify preferences for the transit route | `"transitPreferences": {routingPreference: "LESS_WALKING|FEWER_TRANSFERS"}` | Optional. Specify transit routing preferences. [Learn more](https://developers.google.com/maps/documentation/routes/reference/rest/v2/TransitPreferences.md.txt) |

## Example: Get a route on transit

The following example gets a route on transit with the following parameters:

- Specifies preferences for travel on a train and less walking.

- Requests alternate routes.

- Provides a field mask that returns the transit details:

```json
curl -X POST -H 'content-type: application/json' -d '{
  "origin": {
    "address": "Humberto Delgado Airport, Portugal"
  },
  "destination": {
    "address": "Basílica of Estrela, Praça da Estrela, 1200-667 Lisboa, Portugal"
  },
  "travelMode": "TRANSIT",
  "computeAlternativeRoutes": true,
  "transitPreferences": {
     routingPreference: "LESS_WALKING",
     allowedTravelModes: ["TRAIN"]
  },
}' \
-H 'Content-Type: application/json' \
-H 'X-Goog-Api-Key: YOUR_API_KEY' \
-H 'X-Goog-FieldMask: routes.legs.steps.transitDetails' \
'https://routes.googleapis.com/directions/v2:computeRoutes'
```

The response shows `route.legs.steps.transitDetails` fields for the two routes:

```json
{
  "routes": [
    {
    "legs": [
        {
        "steps": [
          {},
          {},
          {},
          {
          "transitDetails": {
            "stopDetails": {
            "arrivalStop": {
              "name": "Saldanha",
              "location": {
                "latLng": {
                  "latitude": 38.73532,
                  "longitude": -9.14543
                }
              }
            },
            "arrivalTime": "2023-08-26T10:49:42Z",
            "departureStop": {
              "name": "Aeroporto",
              "location": {
                "latLng": {
                  "latitude": 38.769047799999996,
                  "longitude": -9.1284593
                }
              }
            },
            "departureTime": "2023-08-26T10:32:10Z"
              },
              "localizedValues": {
              "arrivalTime": {
                  "time": {
                    "text": "11:49"
                  },
                  "timeZone": "Europe/Lisbon"
              },
              "departureTime": {
                "time": {
                  "text": "11:32"
                },
                "timeZone": "Europe/Lisbon"
              }
            },
              "headsign": "São Sebastião",
              "transitLine": {
                "agencies": [
                  {
                    "name": "Metropolitano de Lisboa, E.P.E.",
                    "phoneNumber": "+351 21 350 0115",
                    "uri": "https://www.metrolisboa.pt/"
                  }
                ],
                "name": "Vermelha",
                "color": "#f23061",
                "nameShort": "Vm",
                "textColor": "#000000",
                "vehicle": {
                  "name": {
                    "text": "Metrô"
                  },
                "type": "SUBWAY",
                "iconUri": "//maps.gstatic.com/mapfiles/transit/iw2/6/subway2.png"
                }
              },
              "stopCount": 11
            }
          },
        {},
        {
          "transitDetails": {
            "stopDetails": {
              "arrivalStop": {
                "name": "Rato",
                "location": {
                  "latLng": {
                    "latitude": 38.7201022,
                    "longitude": -9.1540562
                  }
              }
            },
            "arrivalTime": "2023-08-26T11:01:37Z",
            "departureStop": {
              "name": "Saldanha",
                "location": {
                  "latLng": {
                    "latitude": 38.73527,
                    "longitude": -9.1455200000000012
                  }
                }
              },
              "departureTime": "2023-08-26T10:57:57Z"
            },
            "localizedValues": {
              "arrivalTime": {
                "time": {
                  "text": "12:01"
                },
                "timeZone": "Europe/Lisbon"
              },
              "departureTime": {
                "time": {
                  "text": "11:57"
                },
                "timeZone": "Europe/Lisbon"
              }
            },
            "headsign": "Rato",
            "transitLine": {
              "agencies": [
                {
                "name": "Metropolitano de Lisboa, E.P.E.",
                "phoneNumber": "+351 21 350 0115",
                "uri": "https://www.metrolisboa.pt/"
                }
              ],
              "name": "Amarela",
              "color": "#f2c200",
              "nameShort": "Am",
              "textColor": "#000000",
              "vehicle": {
                "name": {
                  "text": "Metrô"
                },
                "type": "SUBWAY",
                "iconUri": "//maps.gstatic.com/mapfiles/transit/iw2/6/subway2.png"
              }
            },
            "stopCount": 4
          }
        },
        {},
        {},
        {},
        {},
        {},
        {}
        ]
      }
    ]
  }
]
}
```