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ส่งคืนข้อมูลระดับความสูงสำหรับชุดของจุด (ละติจูด/ลองจิจูด)
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 ที่มีข้อมูลระดับความสูงตามที่อธิบายไว้ที่นี่