الحصول على مصفوفة مسار أثناء النقل

احصل على مصفوفة مسار النقل العام تستخدم خيارات وسائل النقل العام المتاحة في المنطقة. قد تشمل خيارات النقل العام الحافلات ومترو الأنفاق والقطارات وغيرها.

للحصول على تفاصيل إضافية، راجع الحصول على مسار عبر وسائل النقل العام.

مثال على مصفوفة مسارات النقل العام

يحسب المثال التالي مصفوفة مسار في النقل العام، وتطلب تذاكر النقل العام بالإضافة إلى أقنعة الحقل المعتادة لمصفوفة المسارات:

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