使用 Google 地图距离矩阵 API 时可以通过多种出行模式吗

Can I pass multiple travel modes when using The Google Maps Distance Matrix API

我需要计算多种出行方式的时间和距离,我尝试通过|分隔的多种出行方式像这样:

https://maps.googleapis.com/maps/api/distancematrix/json?origins=E149AQ&destinations=UB83PH|NW14SA|WC1E7HU|N78DB&mode=walking|bicycling|driving&language=en-GB&key=myKey

但它并没有像我预期的那样工作。

每个请求仅支持一种出行模式。要获得多种出行方式的结果,请提出多个请求。

documentation 暗示但没有明确说明:

可选参数

mode (defaults to driving) — Specifies the mode of transport to use when calculating distance. Valid values and other request details are specified in the Travel Modes section of this document.

出行方式

For the calculation of distances, you may specify the transportation mode to use. By default, distances are calculated for driving directions. The following travel modes are supported:

  • driving (default) indicates distance calculation using the road network.

  • walking requests distance calculation for walking via pedestrian paths & sidewalks (where available).

  • bicycling requests distance calculation for bicycling via bicycle paths & preferred streets (where available).

  • transit requests distance calculation via public transit routes (where available). This value may only be specified if the request includes an API key or a Google Maps API for Work client ID. If you set the mode to transit you can optionally specify either a departure_time or an arrival_time. If neither time is specified, the departure_time defaults to now (that is, the departure time defaults to the current time). You can also optionally include a transit_mode and/or a transit_routing_preference.

Note: Both walking and bicycling directions may sometimes not include clear pedestrian or bicycling paths, so these directions will return warnings in the returned result which you must display to the user.