Get a route matrix on transit
Stay organized with collections
Save and categorize content based on your preferences.
Get a transit route matrix that uses the public transportation options available
in the region. Transit options may include buses, subways, and trains, among
others.
For additional details, see Get a route on transit.
Example transit route matrix
The following example computes a route matrix on transit, requesting the transit
fare in addition to field masks typical for a route matrix:
curl -X POST -d '{
"origins": [
{
"waypoint": {
"location": {
"latLng": {
"latitude": 37.420761,
"longitude": -122.081356
}
}
}
},
{
"waypoint": {
"location": {
"latLng": {
"latitude": 37.403184,
"longitude": -122.097371
}
}
}
}
],
"destinations": [
{
"waypoint": {
"location": {
"latLng": {
"latitude": 37.420999,
"longitude": -122.086894
}
}
}
},
{
"waypoint": {
"location": {
"latLng": {
"latitude": 37.383047,
"longitude": -122.044651
}
}
}
}
],
"travelMode": "TRANSIT"
}' \
-H 'Content-Type: application/json' -H 'X-Goog-Api-Key: YOUR_API_KEY' \
-H 'X-Goog-FieldMask: originIndex,destinationIndex,duration,distanceMeters,status,condition,travelAdvisory.transitFare' \
'https://routes.googleapis.com/distanceMatrix/v2:computeRouteMatrix'
Transit route matrix response
Here is the response from the transit route matrix request:
[
{
"originIndex": 1,
"destinationIndex": 1,
"status": {},
"distanceMeters": 8709,
"duration": "2754s",
"travelAdvisory": {
"transitFare": {
"currencyCode": "USD",
"units": "2",
"nanos": 500000000
}
},
"condition": "ROUTE_EXISTS"
},
{
"originIndex": 0,
"destinationIndex": 0,
"status": {},
"distanceMeters": 530,
"duration": "394s",
"travelAdvisory": {
"transitFare": {}
},
"condition": "ROUTE_EXISTS"
},
{
"originIndex": 1,
"destinationIndex": 0,
"status": {},
"distanceMeters": 2934,
"duration": "740s",
"travelAdvisory": {
"transitFare": {
"currencyCode": "USD",
"units": "2",
"nanos": 500000000
}
},
"condition": "ROUTE_EXISTS"
},
{
"originIndex": 0,
"destinationIndex": 1,
"status": {},
"distanceMeters": 9883,
"duration": "3049s",
"travelAdvisory": {
"transitFare": {
"currencyCode": "USD",
"units": "5"
}
},
"condition": "ROUTE_EXISTS"
}
]
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-28 UTC.
[null,null,["Last updated 2025-08-28 UTC."],[[["\u003cp\u003eObtain a matrix of routes using available public transportation like buses, subways, and trains for a specified region.\u003c/p\u003e\n"],["\u003cp\u003eThe API allows you to calculate travel distances, durations, and even transit fares between multiple origins and destinations using public transit.\u003c/p\u003e\n"],["\u003cp\u003eExample code demonstrates how to make a request to the API using curl, specifying origins, destinations, and desired fields like transit fare.\u003c/p\u003e\n"],["\u003cp\u003eThe response provides a matrix with details for each origin-destination pair, including distance, duration, fare (if applicable), and route existence status.\u003c/p\u003e\n"]]],["This content demonstrates how to obtain a transit route matrix using public transportation like buses, subways, and trains. The process involves sending a POST request to the `computeRouteMatrix` endpoint with origin and destination waypoints, specifying `TRANSIT` as the `travelMode`. The request can include a transit fare request. The response provides details such as distance, duration, status, and transit fare information between specified origin and destination pairs.\n"],null,["# Get a route matrix on transit\n\nGet a transit route matrix that uses the public transportation options available\nin the region. Transit options may include buses, subways, and trains, among\nothers.\n\nFor additional details, see [Get a route on transit](/maps/documentation/routes/transit-route).\n\nExample transit route matrix\n----------------------------\n\nThe following example computes a route matrix on transit, requesting the transit\nfare in addition to field masks typical for a route matrix: \n\n```json\ncurl -X POST -d '{\n \"origins\": [\n {\n \"waypoint\": {\n \"location\": {\n \"latLng\": {\n \"latitude\": 37.420761,\n \"longitude\": -122.081356\n }\n }\n }\n },\n {\n \"waypoint\": {\n \"location\": {\n \"latLng\": {\n \"latitude\": 37.403184,\n \"longitude\": -122.097371\n }\n }\n }\n }\n ],\n \"destinations\": [\n {\n \"waypoint\": {\n \"location\": {\n \"latLng\": {\n \"latitude\": 37.420999,\n \"longitude\": -122.086894\n }\n }\n }\n },\n {\n \"waypoint\": {\n \"location\": {\n \"latLng\": {\n \"latitude\": 37.383047,\n \"longitude\": -122.044651\n }\n }\n }\n }\n ],\n \"travelMode\": \"TRANSIT\"\n}' \\\n-H 'Content-Type: application/json' -H 'X-Goog-Api-Key: YOUR_API_KEY' \\\n-H 'X-Goog-FieldMask: originIndex,destinationIndex,duration,distanceMeters,status,condition,travelAdvisory.transitFare' \\\n'https://routes.googleapis.com/distanceMatrix/v2:computeRouteMatrix'\n```\n\n### Transit route matrix response\n\nHere is the response from the transit route matrix request: \n\n```json\n[\n {\n \"originIndex\": 1,\n \"destinationIndex\": 1,\n \"status\": {},\n \"distanceMeters\": 8709,\n \"duration\": \"2754s\",\n \"travelAdvisory\": {\n \"transitFare\": {\n \"currencyCode\": \"USD\",\n \"units\": \"2\",\n \"nanos\": 500000000\n }\n },\n \"condition\": \"ROUTE_EXISTS\"\n },\n {\n \"originIndex\": 0,\n \"destinationIndex\": 0,\n \"status\": {},\n \"distanceMeters\": 530,\n \"duration\": \"394s\",\n \"travelAdvisory\": {\n \"transitFare\": {}\n },\n \"condition\": \"ROUTE_EXISTS\"\n },\n {\n \"originIndex\": 1,\n \"destinationIndex\": 0,\n \"status\": {},\n \"distanceMeters\": 2934,\n \"duration\": \"740s\",\n \"travelAdvisory\": {\n \"transitFare\": {\n \"currencyCode\": \"USD\",\n \"units\": \"2\",\n \"nanos\": 500000000\n }\n },\n \"condition\": \"ROUTE_EXISTS\"\n },\n {\n \"originIndex\": 0,\n \"destinationIndex\": 1,\n \"status\": {},\n \"distanceMeters\": 9883,\n \"duration\": \"3049s\",\n \"travelAdvisory\": {\n \"transitFare\": {\n \"currencyCode\": \"USD\",\n \"units\": \"5\"\n }\n },\n \"condition\": \"ROUTE_EXISTS\"\n }\n]\n```"]]