تسمح باسترداد الاتجاهات بين المواقع.
يوضح المثال أدناه كيف يمكنك استخدام هذا الصف للحصول على الاتجاهات من "ميدان التايمز" إلى
"سنترال بارك"، مع التوقف أولاً في "مركز لينكولن"، ورسم المواقع الجغرافية والمسار على الخريطة، وإرسال
الخريطة في رسالة إلكترونية.
// 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 | الوصف |
---|---|---|
latitude | Number | خط العرض لنقطة الطريق. |
longitude | Number | خط الطول لنقطة الطريق. |
استرجاع الكرة
DirectionFinder
- كائن DirectionFinder لتسهيل تسلسل المكالمات.
addWaypoint(address)
تضيف نقطة طريق يجب أن يمر بها المسار، باستخدام عنوان.
// Creates a DirectionFinder with a wapoint at Lincoln Center. var directionFinder = Maps.newDirectionFinder().addWaypoint('Lincoln Center, New York, NY');
المَعلمات
الاسم | Type | الوصف |
---|---|---|
address | String | عنوان. |
استرجاع الكرة
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 | الوصف |
---|---|---|
useAlternatives | Boolean | true لعرض مسارات بديلة، أو 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 | الوصف |
---|---|---|
time | Date | وقت الوصول |
استرجاع الكرة
DirectionFinder
- كائن DirectionFinder لتسهيل تسلسل المكالمات
يمكن أيضًا مراجعة
setAvoid(avoid)
لتحديد ما إذا كان سيتم تجنُّب أنواع معيّنة من القيود.
// Creates a DirectionFinder that avoid highways. var directionFinder = Maps.newDirectionFinder().setAvoid(Maps.DirectionFinder.Avoid.HIGHWAYS);
المَعلمات
الاسم | Type | الوصف |
---|---|---|
avoid | String | قيمة ثابتة من 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 | الوصف |
---|---|---|
time | Date | وَقْتُ الْمُغَادَرَة |
استرجاع الكرة
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 | الوصف |
---|---|---|
latitude | Number | خط العرض لموقع النهاية |
longitude | Number | خط الطول لموقع النهاية |
استرجاع الكرة
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 | الوصف |
---|---|---|
address | String | عنوان النهاية |
استرجاع الكرة
DirectionFinder
- كائن DirectionFinder لتسهيل تسلسل المكالمات
setLanguage(language)
لتعيين اللغة التي سيتم استخدامها للاتجاهات.
// Creates a DirectionFinder with the language set to French. var directionFinder = Maps.newDirectionFinder().setLanguage('fr');
المَعلمات
الاسم | Type | الوصف |
---|---|---|
language | String | معرّف اللغة 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 | الوصف |
---|---|---|
mode | String | قيمة ثابتة من Mode |
استرجاع الكرة
DirectionFinder
- كائن DirectionFinder لتسهيل تسلسل المكالمات
يمكن أيضًا مراجعة
setOptimizeWaypoints(optimizeOrder)
تحدّد ما إذا كان سيتم تحسين المسار المقدّم أم لا من خلال إعادة ترتيب نقاط الطريق بترتيب أكثر فعالية (تكون الإعدادات التلقائية على false).
// Creates a DirectionFinder with wapoint optimization enabled. var directionFinder = Maps.newDirectionFinder().setOptimizeWaypoints(true);
المَعلمات
الاسم | Type | الوصف |
---|---|---|
optimizeOrder | Boolean | true لتحسين الترتيب، أو 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 | الوصف |
---|---|---|
latitude | Number | خط العرض لموقع البداية |
longitude | Number | خط الطول لموقع البداية |
استرجاع الكرة
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 | الوصف |
---|---|---|
address | String | عنوان البداية |
استرجاع الكرة
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 | الوصف |
---|---|---|
region | String | رمز المنطقة لاستخدام |
استرجاع الكرة
DirectionFinder
- كائن DirectionFinder لتسهيل تسلسل المكالمات