Class Maps

地圖

可尋找方向、進行地理編碼、取樣海拔高度,以及建立靜態地圖圖片。

屬性

屬性類型說明
DirectionFinderDirectionFinderEnums
StaticMapStaticMapEnums

方法

方法傳回類型簡短說明
decodePolyline(polyline)Number[]將編碼折線字串解碼回點陣列。
encodePolyline(points)String將點陣列編碼為字串。
newDirectionFinder()DirectionFinder建立新的 DirectionFinder 物件。
newElevationSampler()ElevationSampler建立 ElevationSampler 物件。
newGeocoder()Geocoder建立新的 Geocoder 物件。
newStaticMap()StaticMap建立新的 StaticMap 物件。
resetAuthenticationApiKey()void將驗證憑證重設為使用預設配額。
setAuthenticationByApiKey(apiKey)void啟用 API 金鑰來驗證要求,以使用額外配額。
setAuthenticationByApiKey(apiKey, signingKey)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]);
}

參數

名稱類型說明
polylineString要解碼的編碼折線。

回攻員

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);

參數

名稱類型說明
pointsNumber[]要編碼的經緯度組合陣列。

回攻員

String:代表這些點的編碼字串。

另請參閱


newDirectionFinder()

建立新的 DirectionFinder 物件。

回攻員

DirectionFinder:新的方向尋找器物件。


newElevationSampler()

建立 ElevationSampler 物件。

回攻員

ElevationSampler:新的海拔高度取樣器物件。


newGeocoder()

建立新的 Geocoder 物件。

回攻員

Geocoder:新的地理編碼器物件。


newStaticMap()

建立新的 StaticMap 物件。

回攻員

StaticMap:新的靜態地圖物件。


resetAuthenticationApiKey()

重設驗證憑證,使用預設配額。如果您使用 API 金鑰驗證要求,這個方法就適用。如要使用 Maps 方法,但不想提供驗證憑證,可以使用這個方法還原為預設配額。

Maps.resetAuthenticationApiKey();

擲回

Error:如果 setAuthentication(clientId, signingKey) 用於驗證。


setAuthenticationByApiKey(apiKey)

啟用 API 金鑰,驗證要求以使用額外配額。

這個方法用於設定 API 金鑰,以驗證要求。呼叫這個方法時,系統會根據價目表,向與所提供 API 金鑰相關聯的 Google 雲端專案收取配額用量和帳單費用。您可以使用預設配額的 Maps 方法,不必提供驗證憑證。如果您使用 StaticMap,請改用 setAuthenticationByApiKey(apiKey, signingKey) 方法。

Maps.setAuthenticationByApiKey('BBdgJpSbLtAtmkBFjgLt310qT6iekggfDdVqLC0');

參數

名稱類型說明
apiKeyStringAPI 金鑰,可按照快速入門指南中的步驟,從 Google Cloud 控制台取得。

擲回

Error:如果 apiKeynull,或 setAuthentication(clientId, signingKey) 已用於驗證


setAuthenticationByApiKey(apiKey, signingKey)

啟用 API 金鑰和簽署金鑰,驗證要求,以在 StaticMap 中使用額外配額。雖然傳送至 Static Map API 的要求必須使用 signingKey,但這個方法也可用於驗證其他 Google 地圖服務。在這種情況下,系統會忽略 signingKey 參數。

這個方法用於設定 API 金鑰和簽署金鑰,以驗證要求。StaticMap 需要簽署金鑰,為了測試,系統會接受少量未簽署的請求,但一旦達到生產環境中的門檻,這些請求就會開始失敗。詳情請參閱本文

Maps.setAuthenticationByApiKey('BBdgJpSbLtAtmkBFjgLt310qT6iekggfDdVqLC0',
'7_pry-Skg0PKxds-7nvdl91mB5=');

參數

名稱類型說明
apiKeyStringAPI 金鑰,可按照快速入門指南中的步驟,從 Google Cloud 控制台取得。
signingKeyString簽署金鑰,可按照數位簽章指南中的步驟,從 Google Cloud 控制台取得。這是 StaticMap 的必要參數,其他 Google 地圖服務則會忽略此參數。

擲回

Error:如果 apiKeynull,或 setAuthentication(clientId, signingKey) 已用於驗證

另請參閱

已淘汰的方法