特定の場所の標高をサンプリングできます。
次の例では、このクラスを使用して、コロラド州デンバーからグランドジャンクションまでのルート上の最高地点を特定し、地図上にプロットして、その地図を 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 | エンコードされたポリラインを使用して定義された線に沿ったサンプル数の標高データを返します。 |
詳細なドキュメント
sampleLocation(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 オブジェクト。詳細については、こちらをご覧ください。
sampleLocations(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 オブジェクト。詳細については、こちらをご覧ください。
sampleLocations(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 オブジェクト。詳細については、こちらをご覧ください。
samplePath(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 オブジェクト。詳細については、こちらをご覧ください。
samplePath(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 オブジェクト。詳細については、こちらをご覧ください。