Class ElevationSampler

כלי לבחירת נקודות לחישוב גובה

מאפשרת דגימה של גבהים במיקומים מסוימים.
בדוגמה הבאה אפשר לראות איך משתמשים במחלקה הזו כדי לקבוע את הנקודה הכי גבוהה לאורך המסלול מדנוור לגרנד ג'נקשן בקולורדו, לסמן אותה במפה ולשמור את המפה ב-Google Drive.

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

ראה גם

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.
const 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.
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}`);

פרמטרים

שםסוגתיאור
pointsNumber[]מערך של זוגות קווי רוחב ואורך.

חזרה

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

פרמטרים

שםסוגתיאור
encodedPolylineStringקו פוליגון מקודד של נקודות לדגימה.

חזרה

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

פרמטרים

שםסוגתיאור
pointsNumber[]מערך של צמדי קווי רוחב ואורך שמגדירים נתיב לדגימה.
numSamplesIntegerמספר הנקודות לדגימה לאורך נתיב הנקודות.

חזרה

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

פרמטרים

שםסוגתיאור
encodedPolylineStringקו פוליגון מקודד של נקודות שמגדירות נתיב לדגימה.
numSamplesIntegerמספר הנקודות לדגימה לאורך נתיב הנקודות.

חזרה

Object – אובייקט JSON שמכיל את נתוני הגובה, כפי שמתואר כאן.