מאפשרת דגימה של גבהים במיקומים מסוימים.
בדוגמה הבאה אפשר לראות איך משתמשים במחלקה הזו כדי לקבוע את הנקודה הכי גבוהה לאורך המסלול מדנוור לגרנד ג'נקשן בקולורדו, לסמן אותה במפה ולשמור את המפה ב-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
| שיטה | סוג הערך שמוחזר | תיאור קצר |
|---|---|---|
sample | Object | מחזירה נתוני גובה לנקודה אחת (קו רוחב/קו אורך). |
sample | Object | מחזירה נתוני גובה עבור סדרה של נקודות (קו רוחב/קו אורך). |
sample | Object | מחזירה נתוני גובה לנקודות בפוליגון מקודד. |
sample | Object | הפונקציה מחזירה נתוני גובה למספר דגימות לאורך קו, שמוגדר באמצעות סדרה של נקודות. |
sample | Object | מחזירה נתוני גובה למספר דגימות לאורך קו, שמוגדר באמצעות קו פוליגוני מקודד. |
תיעוד מפורט
sample Location(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);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
latitude | Number | קו הרוחב של הנקודה לדגימה. |
longitude | Number | קו האורך של הנקודה לדגימה. |
חזרה
Object – אובייקט JSON שמכיל את נתוני הגובה, כפי שמתואר כאן.
sample Locations(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}`);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
points | Number[] | מערך של זוגות קווי רוחב ואורך. |
חזרה
Object – אובייקט JSON שמכיל את נתוני הגובה, כפי שמתואר כאן.
sample Locations(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}`);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
encoded | String | קו פוליגון מקודד של נקודות לדגימה. |
חזרה
Object – אובייקט JSON שמכיל את נתוני הגובה, כפי שמתואר כאן.
sample Path(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); }
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
points | Number[] | מערך של צמדי קווי רוחב ואורך שמגדירים נתיב לדגימה. |
num | Integer | מספר הנקודות לדגימה לאורך נתיב הנקודות. |
חזרה
Object – אובייקט JSON שמכיל את נתוני הגובה, כפי שמתואר כאן.
sample Path(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); }
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
encoded | String | קו פוליגון מקודד של נקודות שמגדירות נתיב לדגימה. |
num | Integer | מספר הנקודות לדגימה לאורך נתיב הנקודות. |
חזרה
Object – אובייקט JSON שמכיל את נתוני הגובה, כפי שמתואר כאן.