الحصول على مصفوفة مسار أثناء النقل
تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
الحصول على مصفوفة مسارات النقل العام التي تستخدم خيارات النقل العام المتاحة في المنطقة قد تشمل خيارات النقل العام الحافلات ومترو الأنفاق والقطارات وغيرها.
لمزيد من التفاصيل، اطّلِع على الحصول على مسار باستخدام وسائل النقل العام.
مثال على مصفوفة مسارات النقل العام
يحسب المثال التالي مصفوفة طرق النقل العام، ويطلب أجرة النقل العام بالإضافة إلى أقنعة الحقول النموذجية لمصفوفة الطرق:
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 (حسب التوقيت العالمي المتفَّق عليه)
[null,null,["تاريخ التعديل الأخير: 2025-08-17 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\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```"]]