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'),
      },
    },
);

انظر أيضًا

الطُرق

الطريقةنوع القيمة التي تم إرجاعهاوصف قصير
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)

تضبط هذه السمة منطقة لاستخدامها عند تفسير أسماء المواقع الجغرافية. تتطابق رموز المناطق المتاحة مع أسماء نطاقات المستوى الأعلى التي يتم ترميزها حسب البلد والمتاحة على &quot;خرائط Google&quot;. على سبيل المثال، يتوافق رمز المنطقة "uk" مع "maps.google.co.uk".

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

المعلمات

الاسمالنوعالوصف
regionStringرمز المنطقة المطلوب استخدامه.

الإرجاع

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

انظر أيضًا