可尋找方向、進行地理編碼、取樣海拔高度,以及建立靜態地圖圖片。
屬性
| 屬性 | 類型 | 說明 |
|---|---|---|
Direction | Direction | |
Static | Static |
方法
| 方法 | 傳回類型 | 簡短說明 |
|---|---|---|
decode | Number[] | 將編碼折線字串解碼回點陣列。 |
encode | String | 將點陣列編碼為字串。 |
new | Direction | 建立新的 DirectionFinder 物件。 |
new | Elevation | 建立 ElevationSampler 物件。 |
new | Geocoder | 建立新的 Geocoder 物件。 |
new | Static | 建立新的 StaticMap 物件。 |
reset | void | 將驗證憑證重設為使用預設配額。 |
set | void | 啟用 API 金鑰來驗證要求,以使用額外配額。 |
set | void | 啟用 API 金鑰和簽署金鑰,驗證要求,以在 StaticMap 中使用額外配額。 |
內容詳盡的說明文件
decodePolyline(polyline)
將編碼折線字串解碼回點陣列。
// Decodes a string representation of the latitudes and longitudes of // Minneapolis and Milwaukee respectively. const polyline = 'qvkpG`qhxPbgyI_zq_@'; const points = Maps.decodePolyline(polyline); for (let i = 0; i < points.length; i += 2) { Logger.log('%s, %s', points[i], points[i + 1]); }
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
polyline | String | 要解碼的編碼折線。 |
回攻員
Number[] - 經緯度配對陣列 (lat0、long0、lat1、long1...)。
另請參閱
encodePolyline(points)
將點陣列編碼為字串。
// The latitudes and longitudes of New York and Boston respectively. const points = [40.77, -73.97, 42.34, -71.04]; const polyline = Maps.encodePolyline(points);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
points | Number[] | 要編碼的經緯度組合陣列。 |
回攻員
String:代表這些點的編碼字串。
另請參閱
newDirectionFinder()
newElevationSampler()
newGeocoder()
newStaticMap()
resetAuthenticationApiKey()
重設驗證憑證,使用預設配額。如果您使用 API 金鑰驗證要求,這個方法就適用。如要使用 Maps 方法,但不想提供驗證憑證,可以使用這個方法還原為預設配額。
Maps.resetAuthenticationApiKey();
擲回
setAuthenticationByApiKey(apiKey)
啟用 API 金鑰,驗證要求以使用額外配額。
這個方法用於設定 API 金鑰,以驗證要求。呼叫這個方法時,系統會根據價目表,向與所提供 API 金鑰相關聯的 Google 雲端專案收取配額用量和帳單費用。您可以使用預設配額的 Maps 方法,不必提供驗證憑證。如果您使用 StaticMap,請改用 setAuthenticationByApiKey(apiKey, signingKey) 方法。
Maps.setAuthenticationByApiKey('BBdgJpSbLtAtmkBFjgLt310qT6iekggfDdVqLC0');
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
api | String | API 金鑰,可按照快速入門指南中的步驟,從 Google Cloud 控制台取得。 |
擲回
Error:如果 apiKey 為 null,或 已用於驗證setAuthentication(clientId, signingKey)
setAuthenticationByApiKey(apiKey, signingKey)
啟用 API 金鑰和簽署金鑰,驗證要求,以在 StaticMap 中使用額外配額。雖然傳送至 Static Map API 的要求必須使用 signingKey,但這個方法也可用於驗證其他 Google 地圖服務。在這種情況下,系統會忽略 signingKey 參數。
這個方法用於設定 API 金鑰和簽署金鑰,以驗證要求。StaticMap 需要簽署金鑰,為了測試,系統會接受少量未簽署的請求,但一旦達到生產環境中的門檻,這些請求就會開始失敗。詳情請參閱本文。
Maps.setAuthenticationByApiKey('BBdgJpSbLtAtmkBFjgLt310qT6iekggfDdVqLC0', '7_pry-Skg0PKxds-7nvdl91mB5=');
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
api | String | API 金鑰,可按照快速入門指南中的步驟,從 Google Cloud 控制台取得。 |
signing | String | 簽署金鑰,可按照數位簽章指南中的步驟,從 Google Cloud 控制台取得。這是 StaticMap 的必要參數,其他 Google 地圖服務則會忽略此參數。 |
擲回
Error:如果 apiKey 為 null,或 已用於驗證setAuthentication(clientId, signingKey)