Skip to main content

Better route detection

|

The Maps SDK for C++ continuously monitors traffic conditions and automatically evaluates alternative routes to ensure optimal navigation. This feature enhances user experience by providing real-time route adjustments, reducing travel time, and improving overall efficiency, especially in dynamic traffic environments.

Requirements

Route preferences

For this feature to function, the route used in navigation or simulation must be computed with specific settings within the RoutePreferences object:

  • the transportMode needs to be ERouteTransportMode::RTM_Car or ERouteTransportMode::RTM_Lorry
  • the avoidTraffic needs to be ETrafficAvoidance::TA_All or ETrafficAvoidance::TA_Roadblocks
  • the routeType needs to be ERouteType::RT_Fastest

Unless the settings are set as above the better route detection feature will not trigger.

auto prefs = RoutePreferences();

prefs.setRouteType( ERouteType::RT_Fastest );
prefs.setAvoidTraffic( ETrafficAvoidance::TA_Roadblocks );
prefs.setTransportMode( ERouteTransportMode::RTM_Car );

Additional settings can be configured within the RoutePreferences object during route calculation, as long as they do not override or conflict with the required preferences mentioned above.

Traffic

For the callbacks to be triggered, traffic needs to be present of the route on which the navigation is active.

Significant time gain

A newly identified route must have a substantial time delay compared to the current route for it to be considered. The relevant callback will only be triggered if an alternative route offers a time savings of more than five minutes, ensuring that route adjustments are meaningful and beneficial to the user.

warning

The better route detection feature will not function as intended if any of the required conditions outlined above are not met.

Listen for notification events

The startSimulation and startNavigation methods provided by the NavigationService class allow the registration of a NavigationListener that will be notified with the following (and not only) events:

  • onBetterRouteDetected : Triggered when a better route is identified. It provides information such as the newly detected route, its total travel time, the traffic-induced delay on the new route, and the time savings compared to the current route.
  • onBetterRouteInvalidated : Triggered when a previously detected better route is no longer valid. This can occur if the user deviates from the shared trunk of both routes, an even better alternative becomes available, or changing traffic conditions eliminate the previously detected advantage.
  • onBetterRouteRejected : Triggered when no suitable alternative route is found during the better route check.

It is the responsibility of the API user to manage the recommended route. The navigation service does not automatically switch to the better route, requiring explicit handling and implementation by the user.

class MyNavigationListenerImpl : public INavigationListener
{
public:
void onBetterRouteDetected(const Route &route, int travelTime, int delay, int timeGain) override
{
GEM_INFO_LOG("A better route has been detected - total travel time: %d s, traffic delay on the better route: %d s, time gain from current route: %d s", travelTime, delay, timeGain);
// Do something with the route ...
}
void onBetterRouteInvalidated() override
{
GEM_INFO_LOG("The previously found better route is no longer valid");
}
void onBetterRouteRejected(int reason) override
{
GEM_INFO_LOG("The check for better route failed with reason: %d", reason);
}

// Other needed overrides

};

auto yourNavigationListenerImpl = StrongPointerFactory<MyNavigationListenerImpl>();

NavigationService().startSimulation(
route,
yourNavigationListenerImpl,
yourRecorderProgressListenerImpl
);

Force the check for better route

The system automatically performs the better route check at predefined intervals, provided all required conditions are met.

Additionally, the API user can manually trigger the check by calling the checkBetterRoute static method from the Debug class. If a better route is found, the onBetterRouteDetected callback is invoked; otherwise, if no suitable alternative is available, the onBetterRouteRejected callback is triggered - assuming the check was successfully initiated.

Debug().checkBetterRoute();