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لتعيين موقع النهاية الذي يتم حساب الاتجاهات إليه، باستخدام نقطة (خط العرض/lng).
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);

المَعلمات

الاسمTypeالوصف
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');

المَعلمات

الاسمTypeالوصف
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);

المَعلمات

الاسمTypeالوصف
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);

المَعلمات

الاسمTypeالوصف
timeDateوقت الوصول

استرجاع الكرة

DirectionFinder - كائن DirectionFinder لتسهيل تسلسل المكالمات

يمكن أيضًا مراجعة


setAvoid(avoid)

لتحديد ما إذا كان سيتم تجنُّب أنواع معيّنة من القيود.

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

المَعلمات

الاسمTypeالوصف
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);

المَعلمات

الاسمTypeالوصف
timeDateوَقْتُ الْمُغَادَرَة

استرجاع الكرة

DirectionFinder - كائن DirectionFinder لتسهيل تسلسل المكالمات.

يمكن أيضًا مراجعة


setDestination(latitude, longitude)

لتعيين موقع النهاية الذي يتم حساب الاتجاهات إليه، باستخدام نقطة (خط العرض/lng).

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

المَعلمات

الاسمTypeالوصف
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');

المَعلمات

الاسمTypeالوصف
addressStringعنوان النهاية

استرجاع الكرة

DirectionFinder - كائن DirectionFinder لتسهيل تسلسل المكالمات


setLanguage(language)

لتعيين اللغة التي سيتم استخدامها للاتجاهات.

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

المَعلمات

الاسمTypeالوصف
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);

المَعلمات

الاسمTypeالوصف
modeStringقيمة ثابتة من Mode

استرجاع الكرة

DirectionFinder - كائن DirectionFinder لتسهيل تسلسل المكالمات

يمكن أيضًا مراجعة


setOptimizeWaypoints(optimizeOrder)

تحدّد ما إذا كان سيتم تحسين المسار المقدّم أم لا من خلال إعادة ترتيب نقاط الطريق بترتيب أكثر فعالية (تكون الإعدادات التلقائية على false).

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

المَعلمات

الاسمTypeالوصف
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);

المَعلمات

الاسمTypeالوصف
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');

المَعلمات

الاسمTypeالوصف
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');

المَعلمات

الاسمTypeالوصف
regionStringرمز المنطقة لاستخدام

استرجاع الكرة

DirectionFinder - كائن DirectionFinder لتسهيل تسلسل المكالمات

يمكن أيضًا مراجعة