允許取樣特定地點的高度。
以下範例說明如何使用這個類別判斷在科羅拉多州丹佛市到丹麥交界處的最高級點,將地圖繪製成地圖並儲存至 Google 雲端硬碟。
// Get directions from Denver to Grand Junction. var directions = Maps.newDirectionFinder() .setOrigin('Denver, CO') .setDestination('Grand Junction, CO') .setMode(Maps.DirectionFinder.Mode.DRIVING) .getDirections(); var route = directions.routes[0]; // Get elevation samples along the route. var numberOfSamples = 30; var response = Maps.newElevationSampler() .samplePath(route.overview_polyline.points, numberOfSamples) // Determine highest point. var maxElevation = Number.MIN_VALUE; var highestPoint = null; for (var i = 0; i < response.results.length; i++) { var sample = response.results[i]; if (sample.elevation > maxElevation) { maxElevation = sample.elevation; highestPoint = sample.location; } } // Add the path and marker to a map. var map = Maps.newStaticMap() .addPath(route.overview_polyline.points) .addMarker(highestPoint.lat, highestPoint.lng); // Save the map to your drive DocsList.createFile(Utilities.newBlob(map.getMapImage(), 'image/png', 'map.png'));
另請參閱
方法
方法 | 傳回類型 | 簡短說明 |
---|---|---|
sampleLocation(latitude, longitude) | Object | 傳回單一點的海拔高度資料 (lat/lng)。 |
sampleLocations(points) | Object | 傳回一系列點的經緯度資料 (lat/lng)。 |
sampleLocations(encodedPolyline) | Object | 傳回已編碼折線中的點的海拔高度資料。 |
samplePath(points, numSamples) | Object | 傳回線條沿途數組樣本的高度資料,並使用一系列點來定義。 |
samplePath(encodedPolyline, numSamples) | Object | 利用編碼的折線,在線條取得多個樣本的高度資料。 |
內容詳盡的說明文件
sampleLocation(latitude, longitude)
傳回單一點的海拔高度資料 (lat/lng)。
// Gets the elevation of Times Square using a point. var data = Maps.newElevationSampler().sampleLocation(40.759011, -73.984472); Logger.log(data.results[0].elevation);
參數
名稱 | 類型 | 說明 |
---|---|---|
latitude | Number | 取樣點的緯度 |
longitude | Number | 取樣點的經度座標 |
Return 鍵
Object
:包含高度資料的 JSON 物件 (如這裡所述)
sampleLocations(points)
傳回一系列點的經緯度資料 (lat/lng)。
// Gets the elevation of Times Square and Central Park using points. var data = Maps.newElevationSampler().sampleLocations([ // Times Square 40.759011, -73.984472, // Central Park 40.777052, -73.975464 ]); Logger.log('Times Square: ' + data.results[0].elevation); Logger.log('Central Park: ' + data.results[1].elevation);
參數
名稱 | 類型 | 說明 |
---|---|---|
points | Number[] | 經緯度組合的陣列 |
Return 鍵
Object
:包含高度資料的 JSON 物件 (如這裡所述)
sampleLocations(encodedPolyline)
傳回已編碼折線中的點的海拔高度資料。
// Gets the elevation of Times Square and Central Park using a polyline. var data = Maps.newElevationSampler().sampleLocations('yvwwF|aqbMwoBiw@'); Logger.log('Times Square: ' + data.results[0].elevation); Logger.log('Central Park: ' + data.results[1].elevation);
參數
名稱 | 類型 | 說明 |
---|---|---|
encodedPolyline | String | 取樣點的編碼折線 |
Return 鍵
Object
:包含高度資料的 JSON 物件 (如這裡所述)
samplePath(points, numSamples)
傳回線條沿途數組樣本的高度資料,並以一系列點定義。
// Gets the elevation of five points between Times Square and Central Park. var data = Maps.newElevationSampler().samplePath([ // Times Square 40.759011, -73.984472, // Central Park 40.777052, -73.975464 ], 5); for (var i = 0; i < data.results.length; i++) { Logger.log(data.results[i].elevation); }
參數
名稱 | 類型 | 說明 |
---|---|---|
points | Number[] | 定義取樣路徑的路徑經緯度組合 |
numSamples | Integer | 沿著路徑路徑點的樣本數 |
Return 鍵
Object
:包含高度資料的 JSON 物件 (如這裡所述)
samplePath(encodedPolyline, numSamples)
利用編碼的折線,在線條當中傳回多個樣本的高度資料。
// Gets the elevation of five points between Times Square and Central Park. var data = Maps.newElevationSampler().samplePath('yvwwF|aqbMwoBiw@', 5); for (var i = 0; i < data.results.length; i++) { Logger.log(data.results[i].elevation); }
參數
名稱 | 類型 | 說明 |
---|---|---|
encodedPolyline | String | 定義取樣路徑的點編碼折線 |
numSamples | Integer | 沿著路徑路徑點的樣本數 |
Return 鍵
Object
:包含高度資料的 JSON 物件 (如這裡所述)