RouteMatrix 類別
class
google.maps.routes.RouteMatrix
library "routes"
由 RouteMatrix.computeRouteMatrix 計算的一組起點/目的地配對路線矩陣
const {RouteMatrix} = await google.maps.importLibrary("routes");
靜態方法 | |
|---|---|
computeRouteMatrix |
computeRouteMatrix(request)參數:
傳回值:
Promise<{matrix:RouteMatrix}>這項服務會接收起點和目的地清單,並傳回矩陣,其中包含每個起點和目的地組合的路線資訊。 注意:使用這個方法時,您必須設定 ComputeRouteMatrixRequest.fields 屬性,在要求中指定回應欄位遮罩。值為欄位路徑清單。例如:
不建議使用萬用字元回應欄位遮罩 fields: ['*'],原因如下:
|
屬性 | |
|---|---|
rows
readonly |
類型:
Array<RouteMatrixRow>矩陣的列。每一列都對應一個起點,並包含 RouteMatrixItem 陣列,每個陣列代表一條前往目的地的路線。 |
方法 | |
|---|---|
沿用:
toJSON
|
RouteMatrixRow 類別
class
google.maps.routes.RouteMatrixRow
library "routes"
對應至傳遞至 RouteMatrix.computeRouteMatrix 的來源。包含 RouteMatrixItem 清單,每個項目代表前往目的地的路線。
const {RouteMatrixRow} = await google.maps.importLibrary("routes");
屬性 | |
|---|---|
items
readonly |
類型:
Array<RouteMatrixItem>每個目的地的路線資訊。 |
方法 | |
|---|---|
沿用:
toJSON
|
RouteMatrixItem 類別
class
google.maps.routes.RouteMatrixItem
library "routes"
包含為傳遞至 RouteMatrix.computeRouteMatrix 的起點/目的地組合計算的路線資訊。
const {RouteMatrixItem} = await google.maps.importLibrary("routes");
屬性 | |
|---|---|
condition
readonly |
類型:
RouteMatrixItemCondition optional指出是否找到路線。 |
distanceMeters
readonly |
類型:
number optional路線的移動距離 (以公尺為單位)。 |
durationMillis
readonly |
類型:
number optional沿著路線導航所需的時間長度 (以毫秒為單位)。如果將 ComputeRouteMatrixRequest.routingPreference 設為 TRAFFIC_UNAWARE,這個值會與 RouteMatrixItem.staticDurationMillis 相同。如果將 ComputeRouteMatrixRequest.routingPreference 設為 TRAFFIC_AWARE 或 TRAFFIC_AWARE_OPTIMAL,系統會考量路況來計算這個值。注意:如果時間長度超過 2^53 毫秒,這個值會是 Number.POSITIVE_INFINITY。 |
error
readonly |
類型:
RouteMatrixItemError optional計算路線時發生的錯誤。 |
fallbackInfo
readonly |
類型:
FallbackInfo optional在某些情況下,如果伺服器無法根據指定偏好設定,計算特定起點/目的地組合的路線,可能會改用其他計算模式。使用備用廣告時,這個欄位會包含備用廣告回應的詳細資訊。否則這個欄位不會設定。 |
localizedValues
readonly |
類型:
RouteMatrixItemLocalizedValues optionalRouteMatrixItem 屬性的文字表示法。 |
staticDurationMillis
readonly |
類型:
number optional不考慮路況時,沿路線行駛所需的時間。 注意:如果時間長度超過 2^53 毫秒,這個值會是 Number.POSITIVE_INFINITY。 |
travelAdvisory
readonly |
類型:
RouteTravelAdvisory optional路線的其他資訊。 |
ComputeRouteMatrixRequest 介面
介面
google.maps.routes.ComputeRouteMatrixRequest
要求路線矩陣。
屬性 | |
|---|---|
destinations |
類型:
Iterable<string|LatLng|LatLngLiteral|LatLngAltitudeLiteral|DirectionalLocationLiteral|Place|Waypoint>目的地陣列,決定回應矩陣的資料欄。以字串形式傳遞的值可以是地址、Plus Code 或地點資源名稱。系統不會考量海拔高度值。 |
fields |
類型:
Iterable<string>要擷取的欄位集合。為所有欄位指定 ["*"]。 |
origins |
類型:
Iterable<string|LatLng|LatLngLiteral|LatLngAltitudeLiteral|DirectionalLocationLiteral|Place|RouteMatrixOrigin|Waypoint>起點陣列,決定回應矩陣的資料列。以字串形式傳遞的值可以是地址、Plus Code 或地點資源名稱。系統不會考量海拔高度值。 起點和目的地的基數有幾項大小限制:
|
arrivalTime
選填 |
類型:
Date optional抵達時間。 注意:只有在 ComputeRouteMatrixRequest.travelMode 設為 TRANSIT 時,才能設定這個值。您可以指定 ComputeRouteMatrixRequest.departureTime 或 ComputeRouteMatrixRequest.arrivalTime,但不能同時指定兩者。大眾運輸行程最多可顯示過去 7 天或未來 100 天的資訊。 |
departureTime
選填 |
類型:
Date optional出發時間。如未設定這個值,系統會預設為您提出要求的時間。 注意:只有在 ComputeRouteMatrixRequest.travelMode 設為 TRANSIT 時,才能指定過去的時間。大眾運輸行程最多可顯示過去 7 天或未來 100 天的資訊。 |
extraComputations
選填 |
類型:
Iterable<ComputeRouteMatrixExtraComputation> optional |
internalUsageAttributionIds
選填 |
類型:
Iterable<string> optional用於將呼叫歸因於特定套件或 OSS 程式庫的 ID。 |
language
選填 |
類型:
string optionalBCP-47 語言代碼,例如「en-US」或「sr-Latn」。詳情請參閱「Unicode 語言代碼 ID」。如需支援語言清單,請參閱「語言支援」。如未提供這個值,系統會根據 Google Maps JavaScript API 本地化設定推斷語言。否則,系統會根據第一個來源的位置推斷語言。 |
region
選填 |
類型:
string optional區碼,指定為 ccTLD (「頂層網域」) 的兩位字元值。詳情請參閱「國家/地區代碼頂層網域」。如未提供這個值,系統會根據 Google Maps JavaScript API 本地化設定推測區域。否則,系統會根據第一個來源的位置推斷區域。 |
routingPreference
選填 |
類型:
RoutingPreference optional指定如何計算路線矩陣。伺服器會嘗試使用所選路徑偏好設定,計算路徑矩陣。如果轉送偏好設定導致錯誤或延遲時間過長,系統會傳回錯誤。只有在 ComputeRouteMatrixRequest.travelMode 為 DRIVING 或 TWO_WHEELER 時,才能指定這個選項,否則要求會失敗。 |
trafficModel
選填 |
類型:
TrafficModel optional指定計算交通時間時要採用的假設。這項設定會影響 RouteMatrixItem.durationMillis 傳回的值,其中包含根據歷來平均值預估的交通時間。ComputeRouteMatrixRequest.trafficModel 僅適用於將 ComputeRouteMatrixRequest.routingPreference 設為 TRAFFIC_AWARE_OPTIMAL,並將 ComputeRouteMatrixRequest.travelMode 設為 DRIVING 的要求。預設值為 BEST_GUESS。 |
transitPreference
選填 |
類型:
TransitPreference optional |
travelMode
選填 |
類型:
TravelMode optional指定交通方式。 |
units
選填 |
類型:
UnitSystem optional指定顯示欄位的測量單位。如未提供這個值,系統會根據第一個起點的位置推論顯示單位。 |
ComputeRouteMatrixExtraComputation 常數
constants
google.maps.routes.ComputeRouteMatrixExtraComputation
library "routes"
完成要求時要執行的額外運算。詳情請參閱網路服務說明文件。
這些常數也可以做為字串使用。在 TypeScript 中,字串常值是由 ComputeRouteMatrixExtraComputationString 類型定義。
const {ComputeRouteMatrixExtraComputation} = await google.maps.importLibrary("routes");
常數 | |
|---|---|
TOLLS |
矩陣元素的過路費資訊。詳情請參閱網路服務說明文件。 |
RouteMatrixItemCondition 常數
constants
google.maps.routes.RouteMatrixItemCondition
library "routes"
傳回路線的條件。詳情請參閱網路服務說明文件。
這些常數也可以做為字串使用。在 TypeScript 中,字串常值是由 RouteMatrixItemConditionString 類型定義。
const {RouteMatrixItemCondition} = await google.maps.importLibrary("routes");
常數 | |
|---|---|
ROUTE_EXISTS |
系統找到路徑,並為元素填入相應資訊。詳情請參閱網路服務說明文件。 |
ROUTE_NOT_FOUND |
找不到路線。詳情請參閱網路服務說明文件。 |
RouteMatrixItemError 類別
class
google.maps.routes.RouteMatrixItemError
extends Error
library "routes"
特定起點/目的地組合在RouteMatrix.computeRouteMatrix期間發生的錯誤。
const {RouteMatrixItemError} = await google.maps.importLibrary("routes");
方法 | |
|---|---|
沿用:
toJSON
|
RouteMatrixItemLocalizedValues 類別
class
google.maps.routes.RouteMatrixItemLocalizedValues
library "routes"
RouteMatrixItem 的文字表示法。
const {RouteMatrixItemLocalizedValues} = await google.maps.importLibrary("routes");
屬性 | |
|---|---|
distance
readonly |
類型:
string optional路徑矩陣項目的移動距離 (文字格式)。 |
distanceLanguage
readonly |
類型:
string optional距離文字的 BCP-47 語言代碼,例如「en-US」或「sr-Latn」。 詳情請參閱 http://www.unicode.org/reports/tr35/#Unicode_locale_identifier。 |
duration
readonly |
類型:
string optional |
durationLanguage
readonly |
類型:
string optional時間長度文字的 BCP-47 語言代碼,例如「en-US」或「sr-Latn」。 詳情請參閱 http://www.unicode.org/reports/tr35/#Unicode_locale_identifier。 |
staticDuration
readonly |
類型:
string optional不考慮路況的車程時間,以文字形式表示。 |
staticDurationLanguage
readonly |
類型:
string optional靜態時間長度文字的 BCP-47 語言代碼,例如「en-US」或「sr-Latn」。 |
transitFare
readonly |
類型:
string optional大眾運輸票價,以文字形式表示。 |
transitFareLanguage
readonly |
類型:
string optional大眾運輸票價文字的 BCP-47 語言代碼,例如「en-US」或「sr-Latn」。 詳情請參閱 http://www.unicode.org/reports/tr35/#Unicode_locale_identifier。 |
方法 | |
|---|---|
沿用:
toJSON
|
RouteMatrixOrigin 介面
介面
google.maps.routes.RouteMatrixOrigin
ComputeRouteMatrixRequest 的單一來源。
屬性 | |
|---|---|
waypoint |
來源位置。以字串形式傳遞的值可以是地址或 Plus Code。系統不會考量海拔高度值。 |
routeModifiers
選填 |
類型:
RouteModifiers optional以此為起點的每條路線修飾符。 |