Distance Matrix (deprecated)

DistanceMatrixService 类

class google.maps.DistanceMatrixService
library "routes"

const {DistanceMatrixService} = await google.maps.importLibrary("routes");
DistanceMatrixService
DistanceMatrixService()
参数:无
创建 DistanceMatrixService 的新实例,用于向 Google 服务器发送距离矩阵查询。
getDistanceMatrix
getDistanceMatrix(request[, callback])
参数:
用于发出距离矩阵请求。

DistanceMatrixRequest 接口

接口 google.maps.DistanceMatrixRequest

由 DistanceMatrixService 发送的距离矩阵查询,其中包含出发地和目的地位置数组,以及用于计算指标的各种选项。

destinations
类型:Array<string|LatLng|LatLngLiteral|Place>
一个数组,其中包含用作距离和时间计算终点的目的地地址字符串、LatLng 或 Place 对象。必填。
origins
类型:Array<string|LatLng|LatLngLiteral|Place>
一个数组,其中包含用作距离和时间计算起点的地址字符串、LatLng 或 Place 对象。必填。
travelMode
类型:TravelMode
请求的路线类型。必填。
avoidFerries
可选
类型:boolean optional
如果为 true,则指示距离矩阵服务尽可能避开轮渡。可选。
avoidHighways
可选
类型:boolean optional
如果为 true,则指示距离矩阵服务尽可能避开高速公路。可选。
avoidTolls
可选
类型:boolean optional
如果为 true,则指示距离矩阵服务尽可能避开收费路段。可选。
drivingOptions
可选
类型:DrivingOptions optional
仅适用于 travelMode 为 DRIVING 的请求的设置。此对象对其他出行方式没有影响。
language
可选
类型:string optional
语言标识符,用于指定应尽可能以哪种语言返回结果。请参阅支持的语言列表。
region
可选
类型:string optional
用作地址解析请求偏向的区域代码。地区代码接受 ccTLD(“顶级域名”)双字符值。多数 ccTLD 代码都与 ISO 3166-1 代码相同,但也有一些需要注意的例外情况。例如,英国的 ccTLD 为“uk”(.co.uk),而其 ISO 3166-1 代码为“gb”(代表“大不列颠及北爱尔兰联合王国”)。
transitOptions
可选
类型:TransitOptions optional
仅适用于 travelMode 为 TRANSIT 的请求的设置。此对象对其他出行方式没有影响。
unitSystem
可选
类型:UnitSystem optional
显示距离时要使用的首选单位制。可选;默认使用公制。

DistanceMatrixResponse 接口

接口 google.maps.DistanceMatrixResponse

对 DistanceMatrixService 请求的响应,由格式化的出发地和目的地地址以及一系列 DistanceMatrixResponseRow 组成,每个对应一个出发地地址。

destinationAddresses
类型:Array<string>
经过格式化的终点地址。
originAddresses
类型:Array<string>
经过格式化的起点地址。
rows
矩阵的各行,对应起点地址。

DistanceMatrixResponseRow 接口

接口 google.maps.DistanceMatrixResponseRow

DistanceMatrixService 请求响应中的一行,由一系列 DistanceMatrixResponseElement 组成,每个对应一个目的地地址。

elements
该行的各元素,对应终点地址。

DistanceMatrixResponseElement 接口

接口 google.maps.DistanceMatrixResponseElement

DistanceMatrixService 请求响应中的单个元素,其中包含从一个出发地到一个目的地的时长和距离。

distance
类型:Distance
该起点-终点对的距离。此属性可能未定义,因为距离可能未知。
duration
类型:Duration
该起点-终点对的时长。此属性可能未定义,因为持续时间可能未知。
duration_in_traffic
类型:Duration
此起点-终点配对的时长,其中考虑了 trafficModel 属性指示的路况信息。由于时长可能未知,此属性可能为 undefined。仅在发出请求时定义了 drivingOptions 的情况下,专业版方案客户才能使用。
fare
类型:TransitFare
此出发地-目的地配对的总票价。仅适用于公交请求。
status
该特定起点-终点对的状态。

DistanceMatrixStatus 常量

常量 google.maps.DistanceMatrixStatus
库 "routes"

距离矩阵请求完成后,DistanceMatrixService 返回的有关请求的总体顶级状态。按值或使用常量名称指定这些值。例如 'OK' 或 google.maps.DistanceMatrixStatus.OK。

这些常量也可以用作字符串。在 TypeScript 中,字符串字面量由 DistanceMatrixStatusString 类型定义。

const {DistanceMatrixStatus} = await google.maps.importLibrary("routes");
INVALID_REQUEST 提供的请求无效。
MAX_DIMENSIONS_EXCEEDED 该请求包含的起点或终点的数量超过了 25 个。
MAX_ELEMENTS_EXCEEDED 这些起点和终点所产生的结果数量超出了每条查询的限制。
OK 该响应包含有效的结果。
OVER_QUERY_LIMIT 在允许的时间段内请求的元素数量过多。如果您在一段时间后重试,请求应该会成功。
REQUEST_DENIED 该服务拒绝您的网页使用距离矩阵服务。
UNKNOWN_ERROR 由于服务器错误,系统无法处理距离矩阵请求。如果您再试一次,该请求可能会成功。

DistanceMatrixElementStatus 常量

常量 google.maps.DistanceMatrixElementStatus
库 "routes"

距离矩阵请求完成后,DistanceMatrixService 返回的特定出发地-目的地配对的元素级状态。这些值指定为字符串,例如 'OK'。

这些常量也可以用作字符串。在 TypeScript 中,字符串字面量由 DistanceMatrixElementStatusString 类型定义。

const {DistanceMatrixElementStatus} = await google.maps.importLibrary("routes");
NOT_FOUND 无法对该配对的起点和/或终点进行地址解析。
OK 该响应包含有效的结果。
ZERO_RESULTS 在起点和终点之间找不到任何路线。