קבלת מטריצת מסלול בתחבורה ציבורית
קל לארגן דפים בעזרת אוספים
אפשר לשמור ולסווג תוכן על סמך ההעדפות שלך.
לקבל מטריצת מסלולים בתחבורה ציבורית שמשתמשת באפשרויות התחבורה הציבורית שזמינות באזור. אפשרויות התחבורה הציבורית יכולות לכלול אוטובוסים, רכבות תחתית ורכבות, בין היתר.
פרטים נוספים זמינים במאמר איך מקבלים מסלול לתחבורה ציבורית.
דוגמה למטריצת מסלולים של תחבורה ציבורית
בדוגמה הבאה מחושבת מטריצת מסלולים לתחבורה ציבורית, והיא כוללת בקשה למחיר הנסיעה בתחבורה ציבורית בנוסף למסכות השדות האופייניות למטריצת מסלולים:
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'
תגובה של מטריצת מסלולי תחבורה ציבורית
זו התשובה לבקשה של מטריצת מסלולי תחבורה ציבורית:
[
{
"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"
}
]
אלא אם צוין אחרת, התוכן של דף זה הוא ברישיון Creative Commons Attribution 4.0 ודוגמאות הקוד הן ברישיון Apache 2.0. לפרטים, ניתן לעיין במדיניות האתר Google Developers. Java הוא סימן מסחרי רשום של חברת Oracle ו/או של השותפים העצמאיים שלה.
עדכון אחרון: 2025-08-17 (שעון UTC).
[null,null,["עדכון אחרון: 2025-08-17 (שעון 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```"]]