מאפשרת לאחזר מסלולים בין מיקומים.
בדוגמה שלמטה אפשר לראות איך משתמשים במחלקה הזו כדי לקבל את ההוראות מטיימס סקוור לסנטרל פארק, עם עצירה קודם בלינקולן סנטר, לשרטט את המיקומים והנתיב במפה ולשלוח את המפה באימייל.
// Get the directions. const directions = Maps.newDirectionFinder() .setOrigin('Times Square, New York, NY') .addWaypoint('Lincoln Center, New York, NY') .setDestination('Central Park, New York, NY') .setMode(Maps.DirectionFinder.Mode.DRIVING) .getDirections(); const route = directions.routes[0]; // Set up marker styles. let markerLetterCode = 'A'.charCodeAt(); // Add markers to the map. const map = Maps.newStaticMap(); for (let i = 0; i < route.legs.length; i++) { const leg = route.legs[i]; if (i === 0) { // Add a marker for the start location of the first leg only. map.setMarkerStyle( Maps.StaticMap.MarkerSize.MID, Maps.StaticMap.Color.GREEN, String.fromCharCode(markerLetterCode), ); map.addMarker(leg.start_location.lat, leg.start_location.lng); markerLetterCode++; } map.setMarkerStyle( Maps.StaticMap.MarkerSize.MID, Maps.StaticMap.Color.GREEN, String.fromCharCode(markerLetterCode), ); map.addMarker(leg.end_location.lat, leg.end_location.lng); markerLetterCode++; } // Add a path for the entire route. map.addPath(route.overview_polyline.points); // Send the map in an email. const toAddress = Session.getActiveUser().getEmail(); MailApp.sendEmail( toAddress, 'Directions', `Please open: ${map.getMapUrl()}&key=YOUR_API_KEY`, { htmlBody: 'See below.<br/><img src="cid:mapImage">', inlineImages: { mapImage: Utilities.newBlob(map.getMapImage(), 'image/png'), }, }, );
ראה גם
Methods
| שיטה | סוג הערך שמוחזר | תיאור קצר |
|---|---|---|
add | Direction | הוספת ציון דרך שהמסלול חייב לעבור דרכו, באמצעות נקודה (קו רוחב/קו אורך). |
add | Direction | הוספת נקודת ציון שהמסלול חייב לעבור דרכה, באמצעות כתובת. |
clear | Direction | ניקוי קבוצת נקודות הדרך הנוכחית. |
get | Object | קבלת מסלול באמצעות נקודת המוצא, היעד ואפשרויות אחרות שהוגדרו. |
set | Direction | הפרמטר הזה קובע אם צריך להחזיר מסלולים חלופיים, במקום רק את המסלול עם הדירוג הכי גבוה (ברירת המחדל היא false). |
set | Direction | מגדירים את שעת ההגעה הרצויה (אם רלוונטי). |
set | Direction | הגדרה של הימנעות מסוגים מסוימים של הגבלות. |
set | Direction | מגדירים את שעת היציאה הרצויה (אם רלוונטי). |
set | Direction | מגדיר את מיקום הסיום שעבורו יחושב המסלול, באמצעות נקודה (קו רוחב/קו אורך). |
set | Direction | מגדיר את מיקום הסיום שאליו רוצים לחשב את המסלול, באמצעות כתובת. |
set | Direction | הגדרת השפה שבה יוצגו ההנחיות. |
set | Direction | הגדרת אמצעי התחבורה (ברירת המחדל היא נהיגה). |
set | Direction | הפרמטר הזה קובע אם לבצע אופטימיזציה של המסלול שסופק על ידי סידור מחדש של נקודות הציון בסדר יעיל יותר (ברירת המחדל היא false). |
set | Direction | מגדיר את מיקום ההתחלה שממנו יחושבו ההוראות, באמצעות נקודה (קו רוחב/קו אורך). |
set | Direction | מגדיר את מיקום ההתחלה שממנו יחושב המסלול, באמצעות כתובת. |
set | Direction | מגדירה אזור לשימוש כשמפרשים שמות של מיקומים. |
תיעוד מפורט
add Waypoint(latitude, longitude)
הוספת ציון דרך שהמסלול חייב לעבור דרכו, באמצעות נקודה (קו רוחב/קו אורך).
// Creates a DirectionFinder with a wapoint at Lincoln Center. const directionFinder = Maps.newDirectionFinder().addWaypoint( 40.772628, -73.984243, );
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
latitude | Number | קו הרוחב של נקודת הביניים. |
longitude | Number | קו האורך של נקודת הביניים. |
חזרה
Direction — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.
add Waypoint(address)
הוספת נקודת ציון שהמסלול חייב לעבור דרכה, באמצעות כתובת.
// Creates a DirectionFinder with a wapoint at Lincoln Center. const directionFinder = Maps.newDirectionFinder().addWaypoint( 'Lincoln Center, New York, NY', );
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
address | String | כתובת. |
חזרה
Direction — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.
clear Waypoints()
ניקוי קבוצת נקודות הדרך הנוכחית.
const directionFinder = Maps.newDirectionFinder(); // ... // Do something interesting here ... // ... // Remove all waypoints added with addWaypoint(). directionFinder.clearWaypoints();
חזרה
Direction — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.
get Directions()
קבלת מסלול באמצעות נקודת המוצא, היעד ואפשרויות אחרות שהוגדרו.
// Logs how long it takes to walk from Times Square to Central Park. const directions = Maps.newDirectionFinder() .setOrigin('Times Square, New York, NY') .setDestination('Central Park, New York, NY') .setMode(Maps.DirectionFinder.Mode.WALKING) .getDirections(); Logger.log(directions.routes[0].legs[0].duration.text);
חזרה
Object – אובייקט JSON שמכיל את קבוצת המסלולים להוראות ההגעה, כפי שמתואר כאן.
ראה גם
set Alternatives(useAlternatives)
הפרמטר הזה קובע אם להחזיר מסלולים חלופיים, במקום רק את המסלול עם הדירוג הכי גבוה (ברירת המחדל היא false). אם הערך הוא true, המערך routes של האובייקט שמתקבל עשוי להכיל כמה רשומות.
// Creates a DirectionFinder with alternative routes enabled. const directionFinder = Maps.newDirectionFinder().setAlternatives(true);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
use | Boolean | true כדי לחזור למסלולים חלופיים, false אחרת. |
חזרה
Direction — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.
set Arrive(time)
מגדירים את שעת ההגעה הרצויה (אם רלוונטי).
// Creates a DirectionFinder with an arrival time of 2 hours from now. const now = new Date(); const arrive = new Date(now.getTime() + 2 * 60 * 60 * 1000); const directionFinder = Maps.newDirectionFinder().setArrive(arrive);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
time | Date | שעת ההגעה. |
חזרה
Direction — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.
ראה גם
set Avoid(avoid)
הגדרה של הימנעות מסוגים מסוימים של הגבלות.
// Creates a DirectionFinder that avoid highways. const directionFinder = Maps.newDirectionFinder().setAvoid( Maps.DirectionFinder.Avoid.HIGHWAYS, );
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
avoid | String | ערך קבוע מ-Avoid. |
חזרה
Direction — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.
ראה גם
set Depart(time)
מגדירים את שעת היציאה הרצויה (אם רלוונטי).
// Creates a DirectionFinder with a departure time of 1 hour from now. const now = new Date(); const depart = new Date(now.getTime() + 1 * 60 * 60 * 1000); const directionFinder = Maps.newDirectionFinder().setDepart(depart);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
time | Date | שעת היציאה. |
חזרה
Direction — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.
ראה גם
set Destination(latitude, longitude)
מגדיר את מיקום הסיום שעבורו יחושב המסלול, באמצעות נקודה (קו רוחב/קו אורך).
// Creates a DirectionFinder with the destination set to Central Park. const directionFinder = Maps.newDirectionFinder().setDestination( 40.777052, -73.975464, );
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
latitude | Number | קו הרוחב של מיקום הסיום. |
longitude | Number | קו האורך של מיקום הסיום. |
חזרה
Direction — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.
set Destination(address)
מגדיר את מיקום הסיום שאליו רוצים לחשב את המסלול, באמצעות כתובת.
// Creates a DirectionFinder with the destination set to Central Park. const directionFinder = Maps.newDirectionFinder().setDestination( 'Central Park, New York, NY', );
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
address | String | כתובת הסיום. |
חזרה
Direction — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.
set Language(language)
הגדרת השפה שבה יוצגו ההנחיות.
// Creates a DirectionFinder with the language set to French. const directionFinder = Maps.newDirectionFinder().setLanguage('fr');
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
language | String | מזהה שפה בפורמט BCP-47. |
חזרה
Direction — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.
ראה גם
set Mode(mode)
הגדרת אמצעי התחבורה (ברירת המחדל היא נהיגה).
// Creates a DirectionFinder with the mode set to walking. const directionFinder = Maps.newDirectionFinder().setMode( Maps.DirectionFinder.Mode.WALKING, );
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
mode | String | ערך קבוע מ-Mode. |
חזרה
Direction — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.
ראה גם
set Optimize Waypoints(optimizeOrder)
הפרמטר הזה קובע אם לבצע אופטימיזציה של המסלול שסופק על ידי סידור מחדש של נקודות הציון בסדר יעיל יותר (ברירת המחדל היא false).
// Creates a DirectionFinder with wapoint optimization enabled. const directionFinder = Maps.newDirectionFinder().setOptimizeWaypoints(true);
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
optimize | Boolean | true כדי לבצע אופטימיזציה של ההזמנה, או false בכל דרך אחרת. |
חזרה
Direction — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.
ראה גם
set Origin(latitude, longitude)
מגדיר את מיקום ההתחלה שממנו יחושבו ההוראות, באמצעות נקודה (קו רוחב/קו אורך).
// Creates a DirectionFinder with the origin set to Times Square. const directionFinder = Maps.newDirectionFinder().setOrigin( 40.759011, -73.984472, );
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
latitude | Number | קו הרוחב של מיקום המוצא. |
longitude | Number | קו האורך של מיקום המוצא. |
חזרה
Direction — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.
set Origin(address)
מגדיר את מיקום ההתחלה שממנו יחושב המסלול, באמצעות כתובת.
// Creates a DirectionFinder with the origin set to Times Square. const directionFinder = Maps.newDirectionFinder().setOrigin( 'Times Square, New York, NY', );
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
address | String | כתובת ההתחלה. |
חזרה
Direction — מופע של DirectionFinder כדי לאפשר שרשור של שיחות.
set Region(region)
מגדירה אזור לשימוש כשמפרשים שמות של מיקומים. קודי האזורים הנתמכים תואמים לדומיינים הנתמכים ברמה העליונה (ccTLD) במפות Google. לדוגמה, קוד האזור uk מתאים לכתובת maps.google.co.uk.
// Creates a DirectionFinder with the region set to France. const directionFinder = Maps.newDirectionFinder().setRegion('fr');
פרמטרים
| שם | סוג | תיאור |
|---|---|---|
region | String | קוד האזור שבו רוצים להשתמש. |
חזרה
Direction — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.