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.
[[["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-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```"]]