RouteMatrix 类
google.maps.routes.RouteMatrix
类
由 RouteMatrix.computeRouteMatrix
为一组出发地/目的地对计算出的路线矩阵
通过调用 const {RouteMatrix} = await google.maps.importLibrary("routes")
进行访问。
请参阅 Maps JavaScript API 中的库。
静态方法 | |
---|---|
computeRouteMatrix |
computeRouteMatrix(request) 参数:
返回值:
Promise<{matrix:RouteMatrix}> 接受出发地和目的地列表,并返回一个矩阵,其中包含每个出发地和目的地组合的路线信息。 注意:此方法要求您通过设置 ComputeRouteMatrixRequest.fields 属性在请求中指定响应字段掩码。该值是字段路径的列表。例如:
不建议使用通配符响应字段掩码 fields: ['*'] ,因为:
|
属性 | |
---|---|
rows |
类型:
Array<RouteMatrixRow> 矩阵的行。每一行都对应一个出发地,并包含一个 RouteMatrixItem 数组,每个 RouteMatrixItem 都表示前往某个目的地的路线。 |
方法 | |
---|---|
toJSON |
toJSON() 参数:无
返回值:
Object 转换为对象。 |
RouteMatrixRow 类
google.maps.routes.RouteMatrixRow
类
对应于传递给 RouteMatrix.computeRouteMatrix
的来源。包含 RouteMatrixItem
的列表,其中每个项都表示前往目的地的路线。
通过调用 const {RouteMatrixRow} = await google.maps.importLibrary("routes")
进行访问。
请参阅 Maps JavaScript API 中的库。
属性 | |
---|---|
items |
类型:
Array<RouteMatrixItem> 每个目的地的路线信息。 |
方法 | |
---|---|
toJSON |
toJSON() 参数:无
返回值:
Object 转换为对象。 |
RouteMatrixItem 类
google.maps.routes.RouteMatrixItem
类
包含为传递给 RouteMatrix.computeRouteMatrix
的出发地/目的地对计算的路线信息。
通过调用 const {RouteMatrixItem} = await google.maps.importLibrary("routes")
进行访问。
请参阅 Maps JavaScript API 中的库。
属性 | |
---|---|
condition |
类型:
RouteMatrixItemCondition optional 指示是否找到了路线。 |
distanceMeters |
类型:
number optional 相应路线的行程距离(以米为单位)。 |
durationMillis |
类型:
number optional 导航路线所需的时间(以毫秒为单位)。如果您将 ComputeRouteMatrixRequest.routingPreference 设置为 TRAFFIC_UNAWARE ,则此值与 RouteMatrixItem.staticDurationMillis 相同。如果您将 ComputeRouteMatrixRequest.routingPreference 设置为 TRAFFIC_AWARE 或 TRAFFIC_AWARE_OPTIMAL ,则系统会根据路况计算此值。注意:如果时长超过 2^53 毫秒,则此值为 Number.POSITIVE_INFINITY 。 |
error |
类型:
RouteMatrixItemError optional 计算路线时发生的错误。 |
fallbackInfo |
类型:
FallbackInfo optional 在某些情况下,如果服务器无法根据指定偏好设置计算特定起点/终点对的路线,则可能会改用其他计算模式。使用回退时,此字段包含有关回退响应的详细信息。否则,系统将取消设置此字段。 |
localizedValues |
类型:
RouteMatrixItemLocalizedValues optional RouteMatrixItem 的属性的文本表示形式。 |
staticDurationMillis |
类型:
number optional 在不考虑路况的情况下,沿路线行驶所需的时间。 注意:如果时长超过 2^53 毫秒,则此值为 Number.POSITIVE_INFINITY 。 |
travelAdvisory |
类型:
RouteTravelAdvisory optional 有关路线的其他信息。 |
ComputeRouteMatrixRequest 接口
google.maps.routes.ComputeRouteMatrixRequest
接口
对路线矩阵的请求。
属性 | |
---|---|
destinations |
类型:
Iterable<string|LatLng|LatLngLiteral|LatLngAltitudeLiteral|DirectionalLocationLiteral|Place|Waypoint> 目的地数组,用于确定响应矩阵的列。以字符串形式传递的值可以是地址、Plus Code 或 Place 资源名称。系统不会考虑海拔高度值。 |
fields |
类型:
Iterable<string> 要提取的字段的集合。为所有字段指定 ["*"] 。 |
origins |
类型:
Iterable<string|LatLng|LatLngLiteral|LatLngAltitudeLiteral|DirectionalLocationLiteral|Place|RouteMatrixOrigin|Waypoint> 来源数组,用于确定响应矩阵的行。以字符串形式传递的值可以是地址、Plus Code 或 Place 资源名称。系统不会考虑海拔高度值。 来源地和目的地的基数存在以下几项大小限制:
|
arrivalTime optional |
类型:
Date optional 到达时间。 注意:只有当 ComputeRouteMatrixRequest.travelMode 设置为 TRANSIT 时才能设置此项。您可以指定 ComputeRouteMatrixRequest.departureTime 或 ComputeRouteMatrixRequest.arrivalTime ,但不能同时指定这两者。公交行程最多可查询过去 7 天或未来 100 天的行程。 |
departureTime optional |
类型:
Date optional 出发时间。如果您未设置此值,则此值默认为您发出请求的时间。 注意:只有当 ComputeRouteMatrixRequest.travelMode 设置为 TRANSIT 时,您才能指定过去的时间。公交行程最多可查询过去 7 天或未来 100 天的行程。 |
extraComputations optional |
类型:
Iterable<ComputeRouteMatrixExtraComputation> optional 可用于完成请求的额外计算的列表。 注意:这些额外的计算可能会在响应中返回额外的字段。这些额外的字段也必须在 ComputeRouteMatrixRequest.fields 中指定,才能在响应中返回。 |
language optional |
类型:
string optional BCP-47 语言代码,例如“en-US”或“sr-Latn”。如需了解详情,请参阅 Unicode 语言区域标识符。如需查看支持的语言列表,请参阅语言支持。如果您未提供此值,系统会根据您的 Google Maps JavaScript API 本地化设置推断语言。否则,系统会根据第一个来源的位置推断语言。 |
region optional |
类型:
string optional 地区代码,以 ccTLD(“顶级域名”)双字符值的形式指定。如需了解详情,请参阅国家/地区代码顶级网域。如果您未提供此值,系统会根据您的 Google Maps JavaScript API 本地化设置推断区域。否则,系统会根据第一个来源的位置推断区域。 |
routingPreference optional |
类型:
RoutingPreference optional 指定如何计算路线矩阵。服务器会尝试使用所选的路由偏好设置来计算路线矩阵。如果路由偏好设置导致错误或延迟时间过长,则返回错误。只有当 ComputeRouteMatrixRequest.travelMode 为 DRIVING 或 TWO_WHEELER 时,您才能指定此选项,否则请求会失败。 |
trafficModel optional |
类型:
TrafficModel optional 指定计算交通中的时间时要使用的假设。此设置会影响 RouteMatrixItem.durationMillis 中返回的值,该值包含根据历史平均数据预测的交通时间。ComputeRouteMatrixRequest.trafficModel 仅适用于将 ComputeRouteMatrixRequest.routingPreference 设置为 TRAFFIC_AWARE_OPTIMAL 且将 ComputeRouteMatrixRequest.travelMode 设置为 DRIVING 的请求。默认值为 BEST_GUESS 。 |
transitPreference optional |
类型:
TransitPreference optional |
travelMode optional |
类型:
TravelMode optional 指定交通方式。 |
units optional |
类型:
UnitSystem optional 指定显示字段的度量单位。如果您未提供此值,则系统会根据第一个原点的位置推断显示单位。 |
ComputeRouteMatrixExtraComputation 常量
google.maps.routes.ComputeRouteMatrixExtraComputation
常量
要针对 RouteMatrix.computeRouteMatrix
请求执行的额外计算。
通过调用 const {ComputeRouteMatrixExtraComputation} = await google.maps.importLibrary("routes")
进行访问。
请参阅 Maps JavaScript API 中的库。
常量 | |
---|---|
TOLLS |
矩阵项的通行费信息。 |
RouteMatrixItemCondition 常量
google.maps.routes.RouteMatrixItemCondition
常量
给定出发地/目的地对的路线条件。
通过调用 const {RouteMatrixItemCondition} = await google.maps.importLibrary("routes")
进行访问。
请参阅 Maps JavaScript API 中的库。
常量 | |
---|---|
ROUTE_EXISTS |
找到了路线。 |
ROUTE_NOT_FOUND |
找不到任何路线。 |
RouteMatrixItemError 类
google.maps.routes.RouteMatrixItemError
类
在特定来源/目的地对的 RouteMatrix.computeRouteMatrix
期间发生的错误。
此类扩展了 Error
。
通过调用 const {RouteMatrixItemError} = await google.maps.importLibrary("routes")
进行访问。
请参阅 Maps JavaScript API 中的库。
方法 | |
---|---|
toJSON |
toJSON() 参数:无
返回值:
Object 转换为对象。 |
RouteMatrixItemLocalizedValues 类
google.maps.routes.RouteMatrixItemLocalizedValues
类
RouteMatrixItem
的文本表示形式。
通过调用 const {RouteMatrixItemLocalizedValues} = await google.maps.importLibrary("routes")
进行访问。
请参阅 Maps JavaScript API 中的库。
属性 | |
---|---|
distance |
类型:
string optional 路线矩阵项的出行距离(以文本形式表示)。 |
distanceLanguage |
类型:
string optional 距离文本的 BCP-47 语言代码,例如“en-US”或“sr-Latn”。 如需了解详情,请参阅 http://www.unicode.org/reports/tr35/#Unicode_locale_identifier。 |
duration |
类型:
string optional 以文本形式表示的时长,并已本地化为查询区域。考虑路况信息。 注意:如果您未请求流量信息,则此值与 RouteMatrixItemLocalizedValues.staticDuration 的值相同。 |
durationLanguage |
类型:
string optional 时长文本的 BCP-47 语言代码,例如“en-US”或“sr-Latn”。 如需了解详情,请参阅 http://www.unicode.org/reports/tr35/#Unicode_locale_identifier。 |
staticDuration |
类型:
string optional 未考虑路况的行程时长,以文本形式表示。 |
staticDurationLanguage |
类型:
string optional 静态时长文本的 BCP-47 语言代码,例如“en-US”或“sr-Latn”。 |
transitFare |
类型:
string optional 以文本形式表示的公交票价。 |
transitFareLanguage |
类型:
string optional 公交票价文本的 BCP-47 语言代码,例如“en-US”或“sr-Latn”。 如需了解详情,请参阅 http://www.unicode.org/reports/tr35/#Unicode_locale_identifier。 |
方法 | |
---|---|
toJSON |
toJSON() 参数:无
返回值:
Object 转换为对象。 |
RouteMatrixOrigin 接口
google.maps.routes.RouteMatrixOrigin
接口
ComputeRouteMatrixRequest
的单个来源。
属性 | |
---|---|
waypoint |
来源的位置。以字符串形式传递的值可以是地址或公益地址。系统不会考虑海拔高度值。 |
routeModifiers optional |
类型:
RouteModifiers optional 将此作为起点的每条路线的修饰符。 |