Routes Preferred API 目前仅适用于部分客户。如需了解详情,请
与销售人员联系。
计算路线矩阵
使用集合让一切井井有条
根据您的偏好保存内容并对其进行分类。
您可以计算路线的距离和持续时间
使用 ComputeRouteMatrix
方法指定出发地和目的地
是 Routes Preferred API 的实现方法。ComputeRouteMatrix
支持
流式传输 gRPC 调用和 REST HTTP 调用。
如果给定出发地和目的地对的列表,则 ComputeRouteMatrix
计算以每个起点为起点的路线的距离和时长
并在每个目的地结束流的每个元素对应
单个路由的信息
与ComputeRouteMatrix
距离矩阵服务:
- 流式处理允许在整个矩阵之前返回元素
从而缩短延迟时间
ComputeRouteMatrix
提供精细的流量计算选项,
以便您做出质量与延迟权衡决策。
- 请求在 Google 的基础设施内以更高的优先级处理
从而实现更高的可用性
- 您可以指定方向(行进方向)和路边
。
- 您可以请求返回收费信息以及
路线距离和预计到达时间。
启用 ComputeRouteMatrix 方法
若要在代码中使用 ComputeRouteMatrix
方法,您必须先:
启用它。详细了解如何启用 Routes Preferred API
方法,请参阅使用入门。
使用 ComputeRouteMatrix 方法
ComputeRouteMatrix
方法可通过首选路线获得
v1 端点。
如需了解详情,请参阅以下文档:
gRPC:
https://developers.google.com/maps/documentation/routes_preferred/reference/rpc/google.maps.routes.v1
REST:
https://developers.google.com/maps/documentation/routes_preferred/reference/rest/v1/TopLevel/computeRouteMatrix
以下通用步骤介绍了如何使用 gRPC 调用
ComputeRouteMatrix
方法:
从 googleapis 代码库中检出必要的协议缓冲区:
https://github.com/googleapis/googleapis/tree/master/google/maps/routes
请注意,某些构建系统(例如 Go)可能会自动为您执行此操作。
使用您的首选语言和构建工具集,生成相关的
protobuffer 代码。
生成您的请求。必须发送两段必要的元数据
替换为请求:
向 routespreferred.googleapis.com:443
发送请求。您必须使用
TLS 协议
如需查看使用 ComputeRouteMatrix
方法的示例,请参阅
计算路线矩阵(Beta 版)样本。
ComputeRouteMatrix
方法的一个与众不同之处在于,
可以针对整个视频流或单个
元素。例如,如果对流请求执行的
格式错误(例如,起点为零)。但是,如果出现错误
数据流的几个元素(例如,设置一个无效的地点 ID)
则只有受该错误影响的元素包含错误代码。
流返回的元素不一定会返回
按任意顺序展示因此,每个元素都包含一个 origin_index
和 destination_index
。对于指定的出发地和目的地
路线出发地相当于 origins[origin_index]
且路线目的地等效。
至 destinations[destination_index]
。这些数组从零索引。它
对存储出发地和目的地列表订单非常重要。
正在计算通行费
有关计算通行费的信息,请参阅
计算通行费。
有关计算通行费的示例,请参阅
计算路线矩阵样本。
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2024-08-05。
[[["易于理解","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-08-05。"],[[["The `ComputeRouteMatrix` method in the Routes Preferred API calculates distances and durations for multiple origin-destination pairs, offering advantages like streaming results and traffic calculation options."],["It's necessary to enable the `ComputeRouteMatrix` method and understand quota limits before implementation, ensuring compliance with Google Maps Platform terms."],["The method can be accessed through gRPC or REST, with specific steps outlined for using gRPC, including generating protobuffer code and configuring requests."],["Responses include `origin_index` and `destination_index` to correlate results with input data since the order of elements is not guaranteed."],["Toll fee calculation functionality is available within `ComputeRouteMatrix`, allowing developers to incorporate toll costs into route planning."]]],["The `ComputeRouteMatrix` method of the Routes Preferred API calculates route distance and duration for multiple origins and destinations via streaming gRPC or REST HTTP calls. It offers lower latency, fine-grained traffic options, higher availability, waypoint specifications, and toll information. To use it, enable the method, and send requests with API key and field mask. The method returns elements with `origin_index` and `destination_index`. Error codes can be returned for the entire stream or per individual element.\n"]]