Routes Preferred API 目前仅适用于部分客户。如需了解详情,请
与销售人员联系。
Method: computeRoutes
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
在给定一组终端和中间航点的情况下,返回主路线以及可选的备选路线。
注意:此方法要求您在输入中指定响应字段掩码。您可以通过以下两种方式提供响应字段掩码:使用网址参数 $fields
或 fields
,或者使用 HTTP/gRPC 标头 X-Goog-FieldMask
(请参阅可用的网址参数和标头)。该值是以英文逗号分隔的字段路径列表。请参阅有关如何构造字段路径的详细文档。
例如,在此方法中:
- 所有可用字段的字段掩码(适用于人工检查):
X-Goog-FieldMask: *
- 路线级时长、距离和多段线的字段掩码(生产设置示例):
X-Goog-FieldMask:
routes.duration,routes.distanceMeters,routes.polyline.encodedPolyline
Google 不建议使用通配符 (*
) 响应字段掩码,也不在顶级 (routes
) 指定字段掩码,原因如下:
- 仅选择您需要的字段有助于我们的服务器节省计算周期,从而以更低的延迟将结果返回给您。
- 仅在生产作业中选择所需字段可确保稳定的延迟时间性能。我们未来可能会添加更多响应字段,这些新字段可能需要额外的计算时间。如果您选择所有字段,或选择顶级的所有字段,则性能可能会下降,因为我们添加的任何新字段都会自动包含在响应中。
- 仅选择您需要的字段可减小响应大小,从而实现更高的网络吞吐量。
HTTP 请求
POST https://routespreferred.googleapis.com/v1alpha:computeRoutes
网址采用 gRPC 转码语法。
请求正文
请求正文中包含结构如下的数据:
JSON 表示法 |
{
"origin": {
object (Waypoint )
},
"destination": {
object (Waypoint )
},
"intermediates": [
{
object (Waypoint )
}
],
"travelMode": enum (RouteTravelMode ),
"routingPreference": enum (RoutingPreference ),
"polylineQuality": enum (PolylineQuality ),
"polylineEncoding": enum (PolylineEncoding ),
"departureTime": string,
"computeAlternativeRoutes": boolean,
"routeModifiers": {
object (RouteModifiers )
},
"languageCode": string,
"units": enum (Units ),
"optimizeWaypointOrder": boolean
} |
字段 |
origin |
object (Waypoint )
必需。出发地航点。
|
destination |
object (Waypoint )
必需。目的地航点。
|
intermediates[] |
object (Waypoint )
可选。路线沿途的一组航点(不包括航站点),可在以下地点经停或经过。最多支持 25 个中间航点。
|
travelMode |
enum (RouteTravelMode )
可选。指定交通方式。
|
routingPreference |
enum (RoutingPreference )
可选。指定如何计算路线。服务器会尝试使用所选的路由偏好设置来计算路由。如果路由偏好设置导致错误或延迟时间过长,则会返回错误。只有在 travelMode 为 DRIVE 或 TWO_WHEELER 时才能指定此选项,否则请求会失败。
|
polylineQuality |
enum (PolylineQuality )
可选。用于指定您对多段线质量的首选项。
|
polylineEncoding |
enum (PolylineEncoding )
可选。指定多段线的首选编码。
|
departureTime |
string (Timestamp format)
可选。出发时间。如果未设置此值,则此值默认为您发出请求的时间。如果您将此值设置为已过的时间,则请求会失败。 时间戳采用 RFC3339 世界协调时间(UTC,即“祖鲁时”)格式,精确到纳秒,最多九个小数位。示例:"2014-10-02T15:01:23Z" 和 "2014-10-02T15:01:23.045123456Z" 。
|
computeAlternativeRoutes |
boolean
可选。指定是否应计算路线以外的备选路线。对于包含中间航点的请求,系统不会返回备选路线。
|
routeModifiers |
object (RouteModifiers )
可选。一组需要满足的条件,这些条件会影响路线的计算方式。
|
languageCode |
string
可选。BCP-47 语言代码,例如“en-US”或“sr-Latn”。如需了解详情,请参阅 Unicode 语言区域标识符。如需查看受支持语言的列表,请参阅语言支持。如果您未提供此值,系统会根据路线请求的位置推断显示语言。
|
units |
enum (Units )
可选。指定显示字段的测量单位。这包括 NavigationInstruction 中的 instruction 字段。路线、路程、步数、距离和时长所使用的测量单位不受此值的影响。如果您未提供此值,系统会根据请求的位置推断出显示单位。
|
optimizeWaypointOrder |
boolean
如果将 optimizeWaypointOrder 设置为 true,系统会尝试重新排列指定的中间航点,以最大限度地降低路线的总体费用。如果任何中间航点是通过航点,则请求会失败。使用 ComputeRoutesResponse.Routes.optimized_intermediate_waypoint_index 查找新排序。如果未在 X-Goog-FieldMask 标头中请求 routes.optimized_intermediate_waypoint_index ,则请求会失败。如果 optimizeWaypointOrder 设为 false,ComputeRoutesResponse.optimized_intermediate_waypoint_index 为空。
|
响应正文
如果成功,则响应正文包含一个 ComputeRoutesResponse
实例。
授权范围
需要以下 OAuth 范围:
https://www.googleapis.com/auth/maps-platform.routespreferred
如需了解详情,请参阅 OAuth 2.0 概览。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-08-29。
[[["易于理解","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):2025-08-29。"],[[["\u003cp\u003eThe Compute Routes API returns the primary route and optional alternate routes based on specified waypoints.\u003c/p\u003e\n"],["\u003cp\u003eRequests must specify a response field mask using \u003ccode\u003e$fields\u003c/code\u003e, \u003ccode\u003efields\u003c/code\u003e, or the \u003ccode\u003eX-Goog-FieldMask\u003c/code\u003e header for efficient data retrieval.\u003c/p\u003e\n"],["\u003cp\u003eThe request body requires origin and destination waypoints, with optional parameters for travel mode, routing preferences, and more.\u003c/p\u003e\n"],["\u003cp\u003eSuccessful responses provide route details in the \u003ccode\u003eComputeRoutesResponse\u003c/code\u003e object.\u003c/p\u003e\n"],["\u003cp\u003eThe API requires the \u003ccode\u003ehttps://www.googleapis.com/auth/maps-platform.routespreferred\u003c/code\u003e OAuth scope for authorization.\u003c/p\u003e\n"]]],["This service calculates routes between an origin and destination, optionally including intermediate waypoints. It requires a `POST` request to `https://routespreferred.googleapis.com/v1alpha:computeRoutes`, with a JSON request body containing details like origin, destination, travel mode, and routing preferences. It allows for specifying departure time, alternative route calculation, and route modifiers. A field mask, via the `X-Goog-FieldMask` header, is mandatory to control response fields. The method can also optimize waypoint order. Authorization requires the `https://www.googleapis.com/auth/maps-platform.routespreferred` scope.\n"],null,[]]