Class DirectionFinder

כלי לחיפוש מסלולים

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

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

שיטהסוג הערך שמוחזרתיאור קצר
addWaypoint(latitude, longitude)DirectionFinderהוספת ציון דרך שהמסלול חייב לעבור דרכו, באמצעות נקודה (קו רוחב/קו אורך).
addWaypoint(address)DirectionFinderהוספת נקודת ציון שהמסלול חייב לעבור דרכה, באמצעות כתובת.
clearWaypoints()DirectionFinderניקוי קבוצת נקודות הדרך הנוכחית.
getDirections()Objectקבלת מסלול באמצעות נקודת המוצא, היעד ואפשרויות אחרות שהוגדרו.
setAlternatives(useAlternatives)DirectionFinderהפרמטר הזה קובע אם צריך להחזיר מסלולים חלופיים, במקום רק את המסלול עם הדירוג הכי גבוה (ברירת המחדל היא false).
setArrive(time)DirectionFinderמגדירים את שעת ההגעה הרצויה (אם רלוונטי).
setAvoid(avoid)DirectionFinderהגדרה של הימנעות מסוגים מסוימים של הגבלות.
setDepart(time)DirectionFinderמגדירים את שעת היציאה הרצויה (אם רלוונטי).
setDestination(latitude, longitude)DirectionFinderמגדיר את מיקום הסיום שעבורו יחושב המסלול, באמצעות נקודה (קו רוחב/קו אורך).
setDestination(address)DirectionFinderמגדיר את מיקום הסיום שאליו רוצים לחשב את המסלול, באמצעות כתובת.
setLanguage(language)DirectionFinderהגדרת השפה שבה יוצגו ההנחיות.
setMode(mode)DirectionFinderהגדרת אמצעי התחבורה (ברירת המחדל היא נהיגה).
setOptimizeWaypoints(optimizeOrder)DirectionFinderהפרמטר הזה קובע אם לבצע אופטימיזציה של המסלול שסופק על ידי סידור מחדש של נקודות הציון בסדר יעיל יותר (ברירת המחדל היא false).
setOrigin(latitude, longitude)DirectionFinderמגדיר את מיקום ההתחלה שממנו יחושבו ההוראות, באמצעות נקודה (קו רוחב/קו אורך).
setOrigin(address)DirectionFinderמגדיר את מיקום ההתחלה שממנו יחושב המסלול, באמצעות כתובת.
setRegion(region)DirectionFinderמגדירה אזור לשימוש כשמפרשים שמות של מיקומים.

תיעוד מפורט

addWaypoint(latitude, longitude)

הוספת ציון דרך שהמסלול חייב לעבור דרכו, באמצעות נקודה (קו רוחב/קו אורך).

// Creates a DirectionFinder with a wapoint at Lincoln Center.
const directionFinder = Maps.newDirectionFinder().addWaypoint(
    40.772628,
    -73.984243,
);

פרמטרים

שםסוגתיאור
latitudeNumberקו הרוחב של נקודת הביניים.
longitudeNumberקו האורך של נקודת הביניים.

חזרה

DirectionFinder — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.


addWaypoint(address)

הוספת נקודת ציון שהמסלול חייב לעבור דרכה, באמצעות כתובת.

// Creates a DirectionFinder with a wapoint at Lincoln Center.
const directionFinder = Maps.newDirectionFinder().addWaypoint(
    'Lincoln Center, New York, NY',
);

פרמטרים

שםסוגתיאור
addressStringכתובת.

חזרה

DirectionFinder — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.


clearWaypoints()

ניקוי קבוצת נקודות הדרך הנוכחית.

const directionFinder = Maps.newDirectionFinder();
// ...
// Do something interesting here ...
// ...
// Remove all waypoints added with addWaypoint().
directionFinder.clearWaypoints();

חזרה

DirectionFinder — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.


getDirections()

קבלת מסלול באמצעות נקודת המוצא, היעד ואפשרויות אחרות שהוגדרו.

// 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 שמכיל את קבוצת המסלולים להוראות ההגעה, כפי שמתואר כאן.

ראה גם


setAlternatives(useAlternatives)

הפרמטר הזה קובע אם להחזיר מסלולים חלופיים, במקום רק את המסלול עם הדירוג הכי גבוה (ברירת המחדל היא false). אם הערך הוא true, המערך routes של האובייקט שמתקבל עשוי להכיל כמה רשומות.

// Creates a DirectionFinder with alternative routes enabled.
const directionFinder = Maps.newDirectionFinder().setAlternatives(true);

פרמטרים

שםסוגתיאור
useAlternativesBooleantrue כדי לחזור למסלולים חלופיים, false אחרת.

חזרה

DirectionFinder — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.


setArrive(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);

פרמטרים

שםסוגתיאור
timeDateשעת ההגעה.

חזרה

DirectionFinder — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.

ראה גם


setAvoid(avoid)

הגדרה של הימנעות מסוגים מסוימים של הגבלות.

// Creates a DirectionFinder that avoid highways.
const directionFinder = Maps.newDirectionFinder().setAvoid(
    Maps.DirectionFinder.Avoid.HIGHWAYS,
);

פרמטרים

שםסוגתיאור
avoidStringערך קבוע מ-Avoid.

חזרה

DirectionFinder — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.

ראה גם


setDepart(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);

פרמטרים

שםסוגתיאור
timeDateשעת היציאה.

חזרה

DirectionFinder — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.

ראה גם


setDestination(latitude, longitude)

מגדיר את מיקום הסיום שעבורו יחושב המסלול, באמצעות נקודה (קו רוחב/קו אורך).

// Creates a DirectionFinder with the destination set to Central Park.
const directionFinder = Maps.newDirectionFinder().setDestination(
    40.777052,
    -73.975464,
);

פרמטרים

שםסוגתיאור
latitudeNumberקו הרוחב של מיקום הסיום.
longitudeNumberקו האורך של מיקום הסיום.

חזרה

DirectionFinder — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.


setDestination(address)

מגדיר את מיקום הסיום שאליו רוצים לחשב את המסלול, באמצעות כתובת.

// Creates a DirectionFinder with the destination set to Central Park.
const directionFinder = Maps.newDirectionFinder().setDestination(
    'Central Park, New York, NY',
);

פרמטרים

שםסוגתיאור
addressStringכתובת הסיום.

חזרה

DirectionFinder — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.


setLanguage(language)

הגדרת השפה שבה יוצגו ההנחיות.

// Creates a DirectionFinder with the language set to French.
const directionFinder = Maps.newDirectionFinder().setLanguage('fr');

פרמטרים

שםסוגתיאור
languageStringמזהה שפה בפורמט BCP-47.

חזרה

DirectionFinder — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.

ראה גם


setMode(mode)

הגדרת אמצעי התחבורה (ברירת המחדל היא נהיגה).

// Creates a DirectionFinder with the mode set to walking.
const directionFinder = Maps.newDirectionFinder().setMode(
    Maps.DirectionFinder.Mode.WALKING,
);

פרמטרים

שםסוגתיאור
modeStringערך קבוע מ-Mode.

חזרה

DirectionFinder — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.

ראה גם


setOptimizeWaypoints(optimizeOrder)

הפרמטר הזה קובע אם לבצע אופטימיזציה של המסלול שסופק על ידי סידור מחדש של נקודות הציון בסדר יעיל יותר (ברירת המחדל היא false).

// Creates a DirectionFinder with wapoint optimization enabled.
const directionFinder = Maps.newDirectionFinder().setOptimizeWaypoints(true);

פרמטרים

שםסוגתיאור
optimizeOrderBooleantrue כדי לבצע אופטימיזציה של ההזמנה, או false בכל דרך אחרת.

חזרה

DirectionFinder — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.

ראה גם


setOrigin(latitude, longitude)

מגדיר את מיקום ההתחלה שממנו יחושבו ההוראות, באמצעות נקודה (קו רוחב/קו אורך).

// Creates a DirectionFinder with the origin set to Times Square.
const directionFinder = Maps.newDirectionFinder().setOrigin(
    40.759011,
    -73.984472,
);

פרמטרים

שםסוגתיאור
latitudeNumberקו הרוחב של מיקום המוצא.
longitudeNumberקו האורך של מיקום המוצא.

חזרה

DirectionFinder — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.


setOrigin(address)

מגדיר את מיקום ההתחלה שממנו יחושב המסלול, באמצעות כתובת.

// Creates a DirectionFinder with the origin set to Times Square.
const directionFinder = Maps.newDirectionFinder().setOrigin(
    'Times Square, New York, NY',
);

פרמטרים

שםסוגתיאור
addressStringכתובת ההתחלה.

חזרה

DirectionFinder — מופע של DirectionFinder כדי לאפשר שרשור של שיחות.


setRegion(region)

מגדירה אזור לשימוש כשמפרשים שמות של מיקומים. קודי האזורים הנתמכים תואמים לדומיינים הנתמכים ברמה העליונה (ccTLD) במפות Google. לדוגמה, קוד האזור uk מתאים לכתובת maps.google.co.uk.

// Creates a DirectionFinder with the region set to France.
const directionFinder = Maps.newDirectionFinder().setRegion('fr');

פרמטרים

שםסוגתיאור
regionStringקוד האזור שבו רוצים להשתמש.

חזרה

DirectionFinder — האובייקט DirectionFinder כדי לאפשר שרשור של קריאות.

ראה גם