Class DirectionFinder

DirectionFinder

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

// Get the directions.
var 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();
var route = directions.routes[0];

// Set up marker styles.
var markerSize = Maps.StaticMap.MarkerSize.MID;
var markerColor = Maps.StaticMap.Color.GREEN
var markerLetterCode = 'A'.charCodeAt();

// Add markers to the map.
var map = Maps.newStaticMap();
for (var i = 0; i < route.legs.length; i++) {
  var leg = route.legs[i];
  if (i == 0) {
    // Add a marker for the start location of the first leg only.
    map.setMarkerStyle(markerSize, markerColor, String.fromCharCode(markerLetterCode));
    map.addMarker(leg.start_location.lat, leg.start_location.lng);
    markerLetterCode++;
  }
  map.setMarkerStyle(markerSize, markerColor, 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.
var 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')
    }
  }
);

כדאי לעיין גם בפרטים הבאים

שיטות

שיטהסוג הערך שמוחזרתיאור קצר
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.
var directionFinder = Maps.newDirectionFinder().addWaypoint(40.772628, -73.984243);

פרמטרים

שםתיאורהתיאור
latitudeNumberקו הרוחב של ציון הדרך.
longitudeNumberקו האורך של ציון הדרך.

החזרות

DirectionFinder – אובייקט DirectionFinder שנועד לאפשר שרשור של קריאות.


addWaypoint(address)

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

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

פרמטרים

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

החזרות

DirectionFinder – אובייקט DirectionFinder שנועד לאפשר שרשור של קריאות.


clearWaypoints()

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

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

החזרות

DirectionFinder – אובייקט DirectionFinder שמאפשר שרשור של קריאות


getDirections()

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

// Logs how long it would take to walk from Times Square to Central Park.
var 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 alernative routes enabled.
var directionFinder = Maps.newDirectionFinder().setAlternatives(true);

פרמטרים

שםתיאורהתיאור
useAlternativesBooleanTRUE כדי להחזיר מסלולים חלופיים, FALSE אחרת

החזרות

DirectionFinder – אובייקט DirectionFinder שמאפשר שרשור של קריאות


setArrive(time)

הגדרה זו מגדירה את זמן ההגעה הרצוי (כאשר רלוונטי).

// Creates a DirectionFinder with an arrival time of 2 hours from now.
var now = new Date();
var arrive = new Date(now.getTime() + (2 * 60 * 60 * 1000));
var directionFinder = Maps.newDirectionFinder().setArrive(arrive);

פרמטרים

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

החזרות

DirectionFinder – אובייקט DirectionFinder שמאפשר שרשור של קריאות

כדאי לעיין גם בפרטים הבאים


setAvoid(avoid)

קובעת אם להימנע מסוגים מסוימים של הגבלות.

// Creates a DirectionFinder that avoid highways.
var 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.
var now = new Date();
var depart = new Date(now.getTime() + (1 * 60 * 60 * 1000));
var directionFinder = Maps.newDirectionFinder().setDepart(depart);

פרמטרים

שםתיאורהתיאור
timeDateאת שעת היציאה

החזרות

DirectionFinder – אובייקט DirectionFinder שנועד לאפשר שרשור של קריאות.

כדאי לעיין גם בפרטים הבאים


setDestination(latitude, longitude)

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

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

פרמטרים

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

החזרות

DirectionFinder – אובייקט DirectionFinder שמאפשר שרשור של קריאות


setDestination(address)

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

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

פרמטרים

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

החזרות

DirectionFinder – אובייקט DirectionFinder שמאפשר שרשור של קריאות


setLanguage(language)

מגדיר את השפה שבה ייעשה שימוש במסלול.

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

פרמטרים

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

החזרות

DirectionFinder – אובייקט DirectionFinder שמאפשר שרשור של קריאות

כדאי לעיין גם בפרטים הבאים


setMode(mode)

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

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

פרמטרים

שםתיאורהתיאור
modeStringערך קבוע מ-Mode

החזרות

DirectionFinder – אובייקט DirectionFinder שמאפשר שרשור של קריאות

כדאי לעיין גם בפרטים הבאים


setOptimizeWaypoints(optimizeOrder)

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

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

פרמטרים

שםתיאורהתיאור
optimizeOrderBooleanTRUE לביצוע אופטימיזציה של ההזמנה, או FALSE אם לא

החזרות

DirectionFinder – אובייקט DirectionFinder שמאפשר שרשור של קריאות

כדאי לעיין גם בפרטים הבאים


setOrigin(latitude, longitude)

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

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

פרמטרים

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

החזרות

DirectionFinder – אובייקט DirectionFinder שמאפשר שרשור של קריאות


setOrigin(address)

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

// Creates a DirectionFinder with the origin set to Times Square.
var 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.
var directionFinder = Maps.newDirectionFinder().setRegion('fr');

פרמטרים

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

החזרות

DirectionFinder – אובייקט DirectionFinder שמאפשר שרשור של קריאות

כדאי לעיין גם בפרטים הבאים