Routes Preferred API 目前仅适用于部分客户。如需了解详情,请
与销售人员联系。
Method: computeRouteMatrix
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
接受出发地和目的地的列表,并返回包含每种出发地和目的地组合的路线信息的数据流。
注意:此方法要求您在输入中指定响应字段掩码。您可以使用网址参数 $fields
或 fields
,或使用 HTTP/gRPC 标头 X-Goog-FieldMask
提供响应字段掩码(请参阅可用的网址参数和标头)。该值是以英文逗号分隔的字段路径列表。请参阅有关如何构建字段路径的详细文档。
例如,在此方法中:
- 所有可用字段的字段掩码(适用于人工检查):
X-Goog-FieldMask: *
- 路线时长、距离、元素状态、条件和元素索引的字段掩码(正式版设置示例):
X-Goog-FieldMask:
originIndex,destinationIndex,status,condition,distanceMeters,duration
请务必在字段掩码中添加 status
,否则所有消息都将显示为正常。Google 不建议使用通配符 (*
) 响应字段掩码,因为:
- 仅选择您需要的字段有助于我们的服务器节省计算周期,从而让我们能够以更短的延迟时间向您返回结果。
- 在生产作业中仅选择您需要的字段,以确保延迟性能稳定。我们未来可能会添加更多响应字段,而这些新字段可能需要额外的计算时间。如果您选择所有字段,或选择顶级的所有字段,则性能可能会下降,因为我们添加的任何新字段都会自动包含在响应中。
- 仅选择所需字段会使响应大小变小,从而提高网络吞吐量。
HTTP 请求
POST https://routespreferred.googleapis.com/v1alpha:computeRouteMatrix
网址采用 gRPC 转码语法。
请求正文
请求正文中包含结构如下的数据:
字段 |
origins[] |
object (RouteMatrixOrigin )
必需。来源数组,用于确定响应矩阵的行。出发地和目的地的基数有以下几种大小限制:
- 在任何情况下,元素(出发地 × 目的地)的数量都不得超过 625 个。
- 如果 routingPreference 设置为
TRAFFIC_AWARE_OPTIMAL ,元素数量(起点 × 终点)不得超过 100。
- 指定为
placeId 的路点(起点 + 终点)的数量不得超过 50 个。
|
destinations[] |
object (RouteMatrixDestination )
必需。目的地数组,用于确定响应矩阵的列。
|
travelMode |
enum (RouteTravelMode )
可选。指定交通方式。
|
routingPreference |
enum (RoutingPreference )
可选。指定如何计算路线。服务器会尝试使用所选的路由偏好设置来计算路由。如果路由偏好设置导致错误或延迟时间过长,则返回错误。只有在 travelMode 为 DRIVE 或 TWO_WHEELER 时才能指定此选项,否则请求会失败。
|
departureTime |
string (Timestamp format)
可选。出发时间。如果您未设置此值,则默认为您发出请求的时间。如果将此值设置为已经发生的时间,则请求将失败。 时间戳采用 RFC3339 世界协调时间(UTC,即“祖鲁时”)格式,精确到纳秒,最多九个小数位。示例:"2014-10-02T15:01:23Z" 和 "2014-10-02T15:01:23.045123456Z" 。
|
响应正文
如果成功,响应正文将包含 RouteMatrixElement
实例的流。
授权范围
需要以下 OAuth 范围:
https://www.googleapis.com/auth/maps-platform.routespreferred
如需了解详情,请参阅 OAuth 2.0 概览。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-11-10。
[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["没有我需要的信息","missingTheInformationINeed","thumb-down"],["太复杂/步骤太多","tooComplicatedTooManySteps","thumb-down"],["内容需要更新","outOfDate","thumb-down"],["翻译问题","translationIssue","thumb-down"],["示例/代码问题","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2024-11-10。"],[[["Takes a list of origins and destinations, returning route information for each combination."],["Requires specifying a response field mask for optimized performance and data selection."],["Accepts parameters for travel mode, routing preference, and departure time."],["Returns a stream of `RouteMatrixElement` instances containing route details."],["Requires the `https://www.googleapis.com/auth/maps-platform.routespreferred` OAuth scope for authorization."]]],["This method computes route information for multiple origin-destination pairs. It requires a `POST` request to `computeRouteMatrix` with lists of `origins` and `destinations` in the request body. A field mask must be included to specify which data fields to return, with `status` being critical. Optional parameters include `travelMode`, `routingPreference`, and `departureTime`. The response is a stream of `RouteMatrixElement` instances, and the method requires a specific OAuth scope for authorization.\n"]]