Class ElevationSampler

ElevationSampler

特定の場所で標高をサンプリングできます。
次の例は、このクラスを使用して、コロラド州のデンバーからグランド ジャンクションまでのルート上で最高点を確認し、地図上にプロットして、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'));

関連ドキュメント

Methods

メソッド戻り値の型概要
sampleLocation(latitude, longitude)Object単一の地点(緯度/経度)の高度データを返します。
sampleLocations(points)Object一連の地点(緯度/経度)の高度データを返します。
sampleLocations(encodedPolyline)Objectエンコードされたポリライン内の地点の高度データを返します。
samplePath(points, numSamples)Object一連の点を使用して定義された、ラインに沿った多数のサンプルの高度データを返します。
samplePath(encodedPolyline, numSamples)Objectエンコードされたポリラインを使用して定義された、ラインに沿ったサンプル数の高度データを返します。

詳細なドキュメント

sampleLocation(latitude, longitude)

単一の地点の高度データ(緯度/経度)を返します。

// Gets the elevation of Times Square using a point.
var data = Maps.newElevationSampler().sampleLocation(40.759011, -73.984472);
Logger.log(data.results[0].elevation);

パラメータ

名前説明
latitudeNumberサンプリングする点の緯度
longitudeNumberサンプリングする地点の経度

リターン

Object - 高度データを含む JSON オブジェクト。詳しくは、こちらをご覧ください。


sampleLocations(points)

一連の地点(緯度/経度)の高度データを返します。

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

パラメータ

名前説明
pointsNumber[]緯度と経度のペアの配列

リターン

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

パラメータ

名前説明
encodedPolylineStringサンプリングするポイントのエンコードされたポリライン

リターン

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

パラメータ

名前説明
pointsNumber[]サンプリングするパスを定義する緯度と経度のペアの配列
numSamplesIntegerポイントのパスに沿ってサンプリングするポイントの数

リターン

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

パラメータ

名前説明
encodedPolylineStringサンプリングするパスを定義する地点のエンコードされたポリライン
numSamplesIntegerポイントのパスに沿ってサンプリングするポイントの数

リターン

Object - 高度データを含む JSON オブジェクト。詳しくは、こちらをご覧ください。