تنظيم صفحاتك في مجموعات
يمكنك حفظ المحتوى وتصنيفه حسب إعداداتك المفضّلة.
تعرض عمليات احتساب المسار (بما في ذلك إعادة التوجيه) المسار الذي يستغرق أقل وقت للتنقّل باعتباره أفضل مسار تلقائي. ولكن يمكنك تغيير استراتيجية التوجيه ليتم عرض أقصر الطرق البديلة.
يشير مصطلح أقصر إلى المسار الأقصر بين المسارات المثالية استنادًا إلى نموذج التكلفة التلقائي. قد لا يكون المسار الأقصر هو المسار الأقصر على الإطلاق، لأنّ هذا الخيار قد يكون بديلاً سيئًا. على سبيل المثال، إذا كان أقصر مسار على الإطلاق يبلغ 10 كيلومترات ويستغرق 50 دقيقة، وكان هناك مسار آخر يبلغ 15 كيلومترًا ويستغرق 20 دقيقة فقط، سيكون الخيار الثاني هو الأفضل لأنّ توفير 30 دقيقة مقابل قطع 5 كيلومترات إضافية هو خيار منطقي.
بعد ضبط استراتيجية التوجيه لرحلة، لن تتغيّر إلى أن تكتمل الرحلة. لتغيير استراتيجية التوجيه لرحلة حالية، عليك محو الوجهات وإعادة ضبطها باستخدام استراتيجية التوجيه الجديدة.
جارٍ الحصول على تفاصيل المسار
لتحديد استراتيجية المسار الأنسب لنقطة طريق معيّنة،
استدعِ الدالة getRouteInfoForDestination() للحصول على تفاصيل المسار لكلّ من أفضل مسار تلقائي
وأقصر مسار مطلق. وتشمل التفاصيل المدة والمسافة إلى نقطة طريق الوجهة.
بشكلٍ تلقائي، تستبعد حزمة تطوير البرامج للتنقّل على أجهزة iOS المسارات التي تشمل عبّارات. إذا كنت تفضّل تضمين خيارات العبّارات كجزء من مساراتك، يمكنك تعديل إعدادات التوجيه المفضّلة هذه لعرض الرحلة على أجزاء العبّارات من خلال ضبط avoidsFerries على false.
مثال
Swift
self.mapView.navigator?.avoidsFerries=false
Objective-C
self.mapView.navigator.avoidsFerries=NO
تنسيق وسيلة شرح المسار
ضمن استراتيجية التوجيه إلى المسار الأقصر، تعرض وسائط الشرح على طول المسار تفاصيل المسافة. ولكن يمكنك استخدام وسائل شرح مدة الوصول المقدَّرة بدلاً من ذلك.
ضبط تنسيق وسيلة شرح المسار
يمكنك تغيير تنسيق وسيلة شرح المسار من خلال ضبط routeCalloutFormat في GMSMapView. تتخذ السمة routeCalloutFormat إحدى القيم التالية من القيم المحدّدة مسبقًا:
قيمة التعداد
الوصف
GMSNavigationRouteCalloutFormatDefault
تعرض هذه السمة الوقت المتبقي عند استخدام استراتيجية التوجيه التلقائي لأفضل مسار. تعرض هذه السمة المسافة المتبقية عند استخدام استراتيجية توجيه المسار الأقصر
GMSNavigationRouteCalloutFormatTime
تعرض هذه السمة الوقت المتبقي.
GMSNavigationRouteCalloutFormatDistance
تعرض هذه السمة المسافة المتبقية.
مثال
يوضّح مثال الرمز البرمجي التالي كيفية ضبط تنسيق وسيلة شرح المسار.
تاريخ التعديل الأخير: 2025-09-04 (حسب التوقيت العالمي المتفَّق عليه)
[[["يسهُل فهم المحتوى.","easyToUnderstand","thumb-up"],["ساعَدني المحتوى في حلّ مشكلتي.","solvedMyProblem","thumb-up"],["غير ذلك","otherUp","thumb-up"]],[["لا يحتوي على المعلومات التي أحتاج إليها.","missingTheInformationINeed","thumb-down"],["الخطوات معقدة للغاية / كثيرة جدًا.","tooComplicatedTooManySteps","thumb-down"],["المحتوى قديم.","outOfDate","thumb-down"],["ثمة مشكلة في الترجمة.","translationIssue","thumb-down"],["مشكلة في العيّنات / التعليمات البرمجية","samplesCodeIssue","thumb-down"],["غير ذلك","otherDown","thumb-down"]],["تاريخ التعديل الأخير: 2025-09-04 (حسب التوقيت العالمي المتفَّق عليه)"],[[["\u003cp\u003eThe Navigation SDK offers two routing strategies: the default best route (prioritizes time) and the shorter route (prioritizes distance among optimal routes).\u003c/p\u003e\n"],["\u003cp\u003eYou can retrieve route details using \u003ccode\u003egetRouteInfoForDestination()\u003c/code\u003e to compare the default best route and the shorter route.\u003c/p\u003e\n"],["\u003cp\u003eCustomize routing strategy with \u003ccode\u003eGMSNavigationRoutingOptions\u003c/code\u003e, including ferry inclusion with \u003ccode\u003eavoidsFerries\u003c/code\u003e and route callout format with \u003ccode\u003erouteCalloutFormat\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eTo change an active trip's routing strategy, you must clear existing destinations and re-set them with the desired strategy.\u003c/p\u003e\n"],["\u003cp\u003eThe shorter route strategy is designed for Rideshare providers operating in regulated markets where pricing is primarily based on distance traveled.\u003c/p\u003e\n"]]],[],null,["# Adjust routing preferences\n\nRoute calculations (including rerouting) return the route that takes the\nleast amount of time to navigate as the *default best route*. But\nyou can change the routing strategy so that the shorter of the route\nalternatives is returned instead.\n\nThe term *shorter* means the route that is the shortest among optimal route\nbased on our default cost model. The shorter route might not be the *absolute*\nshortest route, since that option might be a poor alternative. For example, if\nthe absolute shortest route is 10 km and takes 50 minutes to navigate and\nanother route is 15 km, but only takes 20 minutes to navigate, the second choice\nis optimal, because spending 30 mins to reduce five km isn't a good trade-off.\n\nOnce you set the routing strategy for a trip, it won't change until the trip\ncompletes. To change the routing strategy for an existing trip, you must clear\nthe destinations and reset them again with the new routing strategy.\n| **Note:** The feature mentioned above is intended for Rideshare providers that operate in regulated markets (such as Europe), who are often required by law to price their services based on the same principles as traditional taxis---which charge based primarily on the distance traveled.\n\nGetting route details\n---------------------\n\nTo determine which route strategy is the optimal choice for a given waypoint,\ncall `getRouteInfoForDestination()` to get route details for both the default\nbest route and the absolute shorter route. Details include the duration and the\ndistance to a destination waypoint.\n\nThese details come from\n[`GMSNavigationRouteInfo`](/maps/documentation/navigation/ios-sdk/reference/objc/Classes/GMSNavigationRouteInfo)\nin the callback.\n\n### Example\n\nThe following code example demonstrates how to get route details for each of the\ntwo routing strategies.\n\n\u003cbr /\u003e\n\n### Swift\n\n\u003cbr /\u003e\n\n let routingOptions = GMSNavigationRoutingOptions()\n navigator?.getRouteInfoForDestination(destination,\n routingOptions: routingOptions) { routeInfo in\n ...\n }\n\n\u003cbr /\u003e\n\n### Objective-C\n\n\u003cbr /\u003e\n\n GMSNavigationRoutingOptions *routingOptions =\n [[GMSNavigationRoutingOptions alloc] init];\n [navigator getRouteInfoForDestination:destination\n withRoutingOptions:routingOptions\n callback:^(GMSNavigationRouteInfo *routeInfo){...}];\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nSetting the routing strategy\n----------------------------\n\nYou can configure the routing strategy by using `GMSNavigationRoutingOptions`,\nand setting the `routingStrategy` when calling `setDestinations()`.\n\n`routingStrategy` takes one of the following enumeration values:\n\n| Enumeration Value | Description |\n|-----------------------------------------|----------------------------------------------------------------------------------------------|\n| GMSNavigationRoutingStrategyDefaultBest | Ranks routes by the Navigation SDK default cost model. This is the default routing strategy. |\n| GMSNavigationRoutingStrategyShorter | Ranks routes by distance. The highest ranking route is the shortest of those returned. |\n\n| **Warning:** This feature is incompatible with the [Hiding Alternate Route](/maps/documentation/navigation/ios-sdk/controls#hiding_alternate_routes) feature. Using these two features at the same time will produce unexpected results.\n\n### Example\n\nThe following code example demonstrates how to set the shorter route routing\nstrategy.\n\n\u003cbr /\u003e\n\n### Swift\n\n\u003cbr /\u003e\n\n let routingOptions = GMSNavigationRoutingOptions(routingStrategy: .shorter)\n navigator?.setDestinations(destinations,\n routingOptions: routingOptions) { routeStatus in\n ...\n }\n\n\u003cbr /\u003e\n\n### Objective-C\n\n\u003cbr /\u003e\n\n GMSNavigationRoutingOptions *routingOptions = [[GMSNavigationRoutingOptions alloc] initWithRoutingStrategy:GMSNavigationRoutingStrategyShorter];\n [navigator setDestinations:destinations\n routingOptions:routingOptions\n callback:^(GMSRouteStatus routeStatus){...}];\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nRoutes that include ferries\n---------------------------\n\nBy default, the Navigation SDK for iOS excludes routes that include ferries. If you prefer to\ninclude ferry options as part of your routes, you can adjust this routing\npreference to expose the trip to ferry segments by setting `avoidsFerries` to\n`false`.\n\n### Example\n\n\u003cbr /\u003e\n\n### Swift\n\n\u003cbr /\u003e\n\n self.mapView.navigator?.avoidsFerries = false\n\n\u003cbr /\u003e\n\n### Objective-C\n\n\u003cbr /\u003e\n\n self.mapView.navigator.avoidsFerries = NO\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e\n\nThe route callout format\n------------------------\n\nUnder the shorter route routing strategy, callouts along the route display\ndistance details. But you can use the ETA callouts instead.\n\n### Configuring the route callout format\n\nYou can change the route callout format by setting `routeCalloutFormat` in\n`GMSMapView`. `routeCalloutFormat` takes one of the following enumeration\nvalues:\n\n| Enumeration Value | Description |\n|-----------------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------|\n| GMSNavigationRouteCalloutFormatDefault | Displays time remaining when using the default best route routing strategy. Displays distance remaining when using the shorter route routing strategy |\n| GMSNavigationRouteCalloutFormatTime | Displays time remaining. |\n| GMSNavigationRouteCalloutFormatDistance | DDisplays distance remaining. |\n\n#### Example\n\nThe following code example demonstrates how to configure the route callout\nformat.\n\n\u003cbr /\u003e\n\n### Swift\n\n\u003cbr /\u003e\n\n self.mapView.routeCalloutFormat = .time\n\n\u003cbr /\u003e\n\n### Objective-C\n\n\u003cbr /\u003e\n\n _mapView.routeCalloutFormat = GMSNavigationRouteCalloutFormatTime;\n\n\u003cbr /\u003e\n\n\u003cbr /\u003e"]]