A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://developers.google.com/maps/documentation/routes/transit-route below:

Get a transit route | Routes API

Skip to main content Get a transit route

Stay organized with collections Save and categorize content based on your preferences.

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: You can also get a route matrix on transit. For an example, see Get a route matrix on transit. 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.

For more information about the response returned by the Routes API, see Review transit route responses.

To get a transit route
  1. Set your origin and destination.

    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.

  4. If needed, set optional parameters. See Set parameters for a transit route.

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.

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. 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: Time is expressed as a timestamp in RFC3339 UTC "Zulu" format. Learn more

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 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 Specify preferences for the transit route "transitPreferences": {routingPreference: "LESS_WALKING|FEWER_TRANSFERS"} Optional. Specify transit routing preferences. Learn more Example: Get a route on transit

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

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:

{
  "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
          }
        },
        {},
        {},
        {},
        {},
        {},
        {}
        ]
      }
    ]
  }
]
}

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-08-14 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-14 UTC."],[[["Transit routes provide navigation using public transportation like buses, subways, and trains, including walking directions to and from stations."],["Unlike other route types, transit routes don't support intermediate waypoints and offer specific parameters like transit preferences and arrival/departure times."],["You can customize the response by using field masks to get details such as transit details, start and end locations, polylines, and fare information."],["The Routes API response for transit includes transit-specific details like stop information, arrival/departure times, headsigns, and transit line details."],["You can set preferences for transit modes (bus, subway, train, etc.) and routing preferences (less walking, fewer transfers) to tailor the route to your needs."]]],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4