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

另请参阅

方法

方法返回类型简介
sampleLocation(latitude, longitude)Object返回单个点(纬度/经度)的海拔数据。
sampleLocations(points)Object用于返回一系列点 (lat/lng) 的海拔数据。
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)

返回一系列点 (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);

参数

名称类型说明
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 对象,如此处所述