Class ElevationSampler

ElevationSampler

Cho phép lấy mẫu độ cao tại các vị trí cụ thể.
Ví dụ bên dưới cho thấy cách bạn có thể sử dụng lớp này để xác định điểm cao nhất dọc theo tuyến đường từ Denver đến Grand Junction ở Colorado, đánh dấu vị trí trên bản đồ và lưu bản đồ vào Google Drive.

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

Xem thêm

Phương thức

Phương thứcLoại dữ liệu trả vềMô tả ngắn
sampleLocation(latitude, longitude)ObjectTrả về dữ liệu độ cao cho một điểm (vĩ độ/lng).
sampleLocations(points)ObjectTrả về dữ liệu độ cao cho một chuỗi điểm (vĩ độ/lng).
sampleLocations(encodedPolyline)ObjectTrả về dữ liệu độ cao cho các điểm trong một hình nhiều đường được mã hoá.
samplePath(points, numSamples)ObjectTrả về dữ liệu độ cao cho một số mẫu dọc theo một đường, được xác định bằng một loạt điểm.
samplePath(encodedPolyline, numSamples)ObjectTrả về dữ liệu độ cao cho một số mẫu dọc theo một đường, được xác định bằng một hình nhiều đường được mã hoá.

Tài liệu chi tiết

sampleLocation(latitude, longitude)

Trả về dữ liệu độ cao cho một điểm (vĩ độ/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);

Tham số

TênLoạiMô tả
latitudeNumbervĩ độ của điểm đến mẫu
longitudeNumberkinh độ của điểm cần lấy mẫu

Cầu thủ trả bóng

Object – Đối tượng JSON chứa dữ liệu độ cao, như được mô tả tại đây


sampleLocations(points)

Trả về dữ liệu độ cao cho một chuỗi điểm (vĩ độ/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);

Tham số

TênLoạiMô tả
pointsNumber[]một mảng gồm các cặp vĩ độ/kinh độ

Cầu thủ trả bóng

Object – Đối tượng JSON chứa dữ liệu độ cao, như được mô tả tại đây


sampleLocations(encodedPolyline)

Trả về dữ liệu độ cao cho các điểm trong một hình nhiều đường được mã hoá.

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

Tham số

TênLoạiMô tả
encodedPolylineStringmột hình nhiều đường được mã hoá gồm các điểm để lấy mẫu

Cầu thủ trả bóng

Object – Đối tượng JSON chứa dữ liệu độ cao, như được mô tả tại đây


samplePath(points, numSamples)

Trả về dữ liệu độ cao cho một số mẫu dọc theo một đường, được xác định bằng một loạt điểm.

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

Tham số

TênLoạiMô tả
pointsNumber[]một mảng các cặp vĩ độ/kinh độ xác định đường dẫn để lấy mẫu
numSamplesIntegersố điểm để lấy mẫu dọc theo lộ trình của các điểm

Cầu thủ trả bóng

Object – Đối tượng JSON chứa dữ liệu độ cao, như được mô tả tại đây


samplePath(encodedPolyline, numSamples)

Trả về dữ liệu độ cao cho một số mẫu dọc theo một đường, được xác định bằng một hình nhiều đường được mã hoá.

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

Tham số

TênLoạiMô tả
encodedPolylineStringmột hình nhiều đường được mã hoá gồm các điểm xác định đường dẫn để lấy mẫu
numSamplesIntegersố điểm để lấy mẫu dọc theo lộ trình của các điểm

Cầu thủ trả bóng

Object – Đối tượng JSON chứa dữ liệu độ cao, như được mô tả tại đây