**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.

## How transit routes differ from other routes

Transit routes, which you request by setting a `travelMode` of
`TRANSIT`, differ from routes using different travel mode 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 [`stepsOverview`](https://developers.google.com/maps/documentation/javascript/reference/route.md.txt#RouteLeg.stepsOverview) field mask). |
| Cannot specify how and if to include traffic data |   |
| Cannot specify route features to avoid |   |
| Can only specify `transitPreferences`. For details, see [`TransitPreference`](https://developers.google.com/maps/documentation/javascript/reference/route.md.txt#ComputeRoutesRequest.transitPreference). |   |

## To get a transit route

1. Set your origin and destination.  

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

2. Set the `travelMode` to `TRANSIT`.
3. Add the appropriate field masks to get the response you need. See [Request the transit route fields you need](https://developers.google.com/maps/documentation/javascript/routes/route-transit.md.txt#request-transit-route-fields).
4. If needed, set optional parameters. See [Set parameters for a transit route](https://developers.google.com/maps/documentation/javascript/routes/route-transit.md.txt#set-transit-parameters)

### 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. | `*` |
| Transit details for route legs. | `legs` |
| Estimated fare for each step of the route, and localized estimated fare. | `travelAdvisory` |
| Localized text for duration and distance | `localizedValues` |

### 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/javascript/reference/route.md.txt#ComputeRoutesRequest.travelMode). |
| Set an arrival or departure time | `arrivalTime: new Date(yyyy-mm-ddThh:mm:ssZ)` OR `departureTime: new Date(yyyy-mm-ddThh:mm:ssZ)` | Optional. You can specify either arrival time or departure time. If neither time is specified, the `departureTime` 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 `Date` object. 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 `computeRoutes` compute up to 3 additional routes, when available. [Learn more](https://developers.google.com/maps/documentation/javascript/reference/route.md.txt#ComputeRoutesRequest) |
| Specify preferences for the transit type | `transitPreference: {allowedTransitModes: ["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/javascript/reference/route.md.txt#TransitPreference) |
| Specify preferences for the transit route | `transitPreference: {routingPreference: "LESS_WALKING|FEWER_TRANSFERS"}` | Optional. Specify transit routing preferences. [Learn more](https://developers.google.com/maps/documentation/javascript/reference/route.md.txt#TransitPreference) |

## Example request

The following example shows how to request a transit route:

```javascript
const request = {
  origin: 'Hunters Point San Francisco, CA 94124',
  destination: '201 Marine Dr, San Francisco, CA 94129',
  travelMode: 'TRANSIT',
  departureTime: new Date(),
  transitPreference: {
    allowedTransitModes: ['BUS', 'SUBWAY', 'TRAIN', 'LIGHT_RAIL', 'RAIL'],
    routingPreference: 'FEWER_TRANSFERS', // Alternatively, 'LESS_WALKING'.
  },
  fields: ['path', 'legs', 'travelAdvisory', 'localizedValues'],
};
    
```