可讓您在特定位置取樣海拔高度。
以下範例說明如何使用這個類別,判斷從科羅拉多州丹佛到格蘭 Junction 的路線最高點,並在地圖上繪製該點,然後將地圖儲存至 Google 雲端硬碟。
// Get directions from Denver to Grand Junction. const directions = Maps.newDirectionFinder() .setOrigin('Denver, CO') .setDestination('Grand Junction, CO') .setMode(Maps.DirectionFinder.Mode.DRIVING) .getDirections(); const route = directions.routes[0]; // Get elevation samples along the route. const numberOfSamples = 30; const response = Maps.newElevationSampler().samplePath( route.overview_polyline.points, numberOfSamples, ); // Determine highest point. let highestLocation = null; let highestElevation = Number.MIN_VALUE; for (const sample of response.results) { if (sample.elevation > highestElevation) { highestElevation = sample.elevation; highestLocation = sample.location; } } // Add the path and marker to a map. const map = Maps.newStaticMap() .addPath(route.overview_polyline.points) .addMarker(highestLocation.lat, highestLocation.lng); // Save the map to your drive DriveApp.createFile( Utilities.newBlob(map.getMapImage(), 'image/png', 'map.png'), );
另請參閱
方法
| 方法 | 傳回類型 | 簡短說明 |
|---|---|---|
sample | Object | 傳回單一點 (緯度/經度) 的海拔高度資料。 |
sample | Object | 傳回一系列點 (緯度/經度) 的海拔高度資料。 |
sample | Object | 傳回編碼折線中各點的海拔高度資料。 |
sample | Object | 傳回沿線多個樣本的海拔高度資料,並使用一系列點定義路線。 |
sample | Object | 傳回沿線多個樣本的海拔高度資料,並使用編碼折線定義。 |
內容詳盡的說明文件
sample Location(latitude, longitude)
傳回單一點 (緯度/經度) 的海拔高度資料。
// Gets the elevation of Times Square using a point. const data = Maps.newElevationSampler().sampleLocation(40.759011, -73.984472); Logger.log(data.results[0].elevation);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
latitude | Number | 要取樣的點的緯度。 |
longitude | Number | 要取樣的點的經度。 |
回攻員
Object:包含海拔高度資料的 JSON 物件,如這裡所述。
sample Locations(points)
傳回一系列點 (緯度/經度) 的海拔高度資料。
// Gets the elevation of Times Square and Central Park using points. const 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[] | 經緯度組合的陣列。 |
回攻員
Object:包含海拔高度資料的 JSON 物件,如這裡所述。
sample Locations(encodedPolyline)
傳回編碼折線中各點的海拔高度資料。
// Gets the elevation of Times Square and Central Park using a polyline. const data = Maps.newElevationSampler().sampleLocations('yvwwF|aqbMwoBiw@'); Logger.log(`Times Square: ${data.results[0].elevation}`); Logger.log(`Central Park: ${data.results[1].elevation}`);
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
encoded | String | 要取樣的點的編碼折線。 |
回攻員
Object:包含海拔高度資料的 JSON 物件,如這裡所述。
sample Path(points, numSamples)
傳回沿線多個樣本的海拔高度資料,並使用一系列點定義路線。
// Gets the elevation of five points between Times Square and Central Park. const data = Maps.newElevationSampler().samplePath( [ // Times Square 40.759011, -73.984472, // Central Park 40.777052, -73.975464, ], 5, ); for (let i = 0; i < data.results.length; i++) { Logger.log(data.results[i].elevation); }
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
points | Number[] | 經緯度組合陣列,定義要取樣的路徑。 |
num | Integer | 沿著點路徑取樣的點數。 |
回攻員
Object:包含海拔高度資料的 JSON 物件,如這裡所述。
sample Path(encodedPolyline, numSamples)
傳回沿線多個樣本的海拔高度資料,並使用編碼折線定義線條。
// Gets the elevation of five points between Times Square and Central Park. const data = Maps.newElevationSampler().samplePath('yvwwF|aqbMwoBiw@', 5); for (let i = 0; i < data.results.length; i++) { Logger.log(data.results[i].elevation); }
參數
| 名稱 | 類型 | 說明 |
|---|---|---|
encoded | String | 定義取樣路徑的編碼折線。 |
num | Integer | 沿著點路徑取樣的點數。 |
回攻員
Object:包含海拔高度資料的 JSON 物件,如這裡所述。