Routes Preferred API 目前仅适用于部分客户。如需了解详情,请
与销售人员联系。
Method: computeCustomRoutes
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
给定一组航点和中间航点以及路线目标,将根据路线目标计算最佳路线。返回最快路线和最短路线作为参考路线。
注意:此方法要求您在输入中指定响应字段掩码。您可以通过以下两种方式提供响应字段掩码:使用网址参数 $fields
或 fields
,或者使用 HTTP/gRPC 标头 X-Goog-FieldMask
(请参阅可用的网址参数和标头)。该值是以英文逗号分隔的字段路径列表。请参阅有关如何构建字段路径的详细文档。
例如,在此方法中:
- 所有可用字段的字段掩码(适用于人工检查):
X-Goog-FieldMask: *
- 路线距离、时长、令牌和收费信息的字段掩码:
X-Goog-FieldMask:
routes.route.distanceMeters,routes.route.duration,routes.token,routes.route.travelAdvisory.tollInfo
Google 不建议使用通配符 (*
) 响应字段掩码,也不建议在顶级 (routes
) 指定字段掩码,因为:
- 仅选择您需要的字段有助于我们的服务器节省计算周期,从而以更低的延迟将结果返回给您。
- 在生产作业中仅选择您需要的字段,以确保延迟性能稳定。我们未来可能会添加更多响应字段,而这些新字段可能需要额外的计算时间。如果您选择所有字段,或者选择顶级的所有字段,则可能会出现性能下降,因为我们添加的任何新字段都会自动包含在响应中。
- 仅选择所需字段会使响应大小变小,从而提高网络吞吐量。
HTTP 请求
POST https://routespreferred.googleapis.com/v1alpha:computeCustomRoutes
网址采用 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,
"routeModifiers": {
object (RouteModifiers )
},
"routeObjective": {
object (RouteObjective )
},
"languageCode": string,
"units": enum (Units )
} |
字段 |
origin |
object (Waypoint )
必需。出发地航点。
|
destination |
object (Waypoint )
必需。目的地航点。
|
intermediates[] |
object (Waypoint )
可选。路线沿途的一组航点(不包括航站点),可在以下地点经停或经过。最多支持 25 个中间航点。
|
travelMode |
enum (RouteTravelMode )
可选。指定交通方式。仅支持 DRIVE 和“TWO_WHEELER”。
|
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" 。
|
routeModifiers |
object (RouteModifiers )
可选。一组要满足的条件,这些条件会影响路线的计算方式。
|
routeObjective |
object (RouteObjective )
必需。要优化的路线目标。
|
languageCode |
string
可选。BCP-47 语言代码,例如“en-US”或“sr-Latn”。如需了解详情,请参阅 Unicode 语言区域标识符。如需查看受支持语言的列表,请参阅语言支持。如果您未提供此值,系统会根据路线请求的位置推断出显示语言。
|
units |
enum (Units )
可选。指定显示字段的测量单位。这包括 NavigationInstruction 中的 instruction 字段。路线、路段、步数距离和时长所用的衡量单位不受此值的影响。如果您未提供此值,系统会根据请求的位置推断显示单位。
|
授权范围
需要以下 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\u003eGiven terminal and intermediate waypoints, and a route objective, this method computes the best route, also returning the fastest and shortest routes for reference.\u003c/p\u003e\n"],["\u003cp\u003eRequests require specifying a response field mask for optimized performance and to manage response size.\u003c/p\u003e\n"],["\u003cp\u003eThe request body includes origin, destination, intermediates, travel mode, routing preferences, and other route-specific parameters.\u003c/p\u003e\n"],["\u003cp\u003eSuccessful responses contain a \u003ccode\u003eComputeCustomRoutesResponse\u003c/code\u003e object with the calculated routes.\u003c/p\u003e\n"],["\u003cp\u003eAuthorization requires the \u003ccode\u003ehttps://www.googleapis.com/auth/maps-platform.routespreferred\u003c/code\u003e scope.\u003c/p\u003e\n"]]],["This document outlines a method to compute the best route based on a given objective, along with the fastest and shortest routes as references. It requires a POST HTTP request to `https://routespreferred.googleapis.com/v1alpha:computeCustomRoutes` with a JSON request body. The request body requires the origin, destination, and route objective. It can also include intermediate waypoints, travel mode, routing preference, and other optional parameters. The response provides a `ComputeCustomRoutesResponse`, and the method needs the `https://www.googleapis.com/auth/maps-platform.routespreferred` authorization scope. It is recommended to specify a field mask to limit the response size and improve latency.\n"],null,[]]