Skip to content

Intersection Guidance

Intersection guidance

This tutorial shows how to handle intersection guidance instructions.

Get started

The navigation service provides intersection guidance information for a good turn-by-turn experience in navigation mode. It provides a lane-level view of the road at the intersection and indicates which lane is preferred to make the turn. Intersection guidance requires the navigation and alert component to be enabled at the creation of a navigation service to provide the active route by navigation component and the preferred turn-by-turn lane guidance by alert component. A navigation service created with the navigation and alert component enabled will have intersection guidance turned on by default.

1
2
3
4
5
6
7
// enable navigation and alert component
tn::drive::NavigationServiceOptions options;
options.enable_navigation = true;
options.enable_alert = true;

const auto navigationService = tn::drive::api::NavigationServiceFactory::createNavigationService(
    options, system, settings, mapContent, directionService);

Turn it off at the creation of a navigation service if intersection guidance is not needed. Once turned off, you will not receive the intersection guidance even the navigation and alert component is enabled.

1
2
3
4
5
6
7
// turn off intersection guidance
const auto settings = tn::foundation::Settings::Builder()
    .setString(tn::drive::api::SettingConstants::SETTING_INTERSECTION_GUIDANCE, "false")
    .build();

const auto navigationService = tn::drive::api::NavigationServiceFactory::createNavigationService(
    options, system, settings, mapContent, directionService);

Customize intersection guidance trigger distance

Intersection guidance trigger distances can be configured at the creation of a navigation service if needed.

// custom the trigger distance threshold
const auto settings = tn::foundation::Settings::Builder()
    .setString(tn::drive::api::SettingConstants::SETTING_INTERSECTION_HIGHWAY_DISPLAY_DISTANCE, "300")
    .setString(tn::drive::api::SettingConstants::SETTING_INTERSECTION_LOCAL_STREET_DISPLAY_DISTANCE, "100")
    .build();

// enable navigation and alert component
tn::drive::NavigationServiceOptions options;
options.enable_navigation = true;
options.enable_alert = true;

const auto navigationService = tn::drive::api::NavigationServiceFactory::createNavigationService(
    options, system, settings, mapContent, directionService);

Handle intersection guidance in navigation mode

Make a customized guidance listener to handle intersection guidance updates. The guidance info is used for map display rendering.

class GuidanceObserver : public tn::drive::api::GuidanceEventListener
{
public:
    void onIntersectionGuidanceUpdated(const tn::drive::models::v1::IntersectionGuidance& info) override
    {
        // the intersection is newly detected
        if (tn::drive::models::v1::IntersectionGuidance::Status::Detected == info.status)
        {
            // map display starts rendering the guidance data(info.data).
        }
        // the intersection is passed
        else if (tn::drive::models::v1::IntersectionGuidance::Status::Passed == info.status)
        {
            // map display clears the rendered data(info.data).
        }
    }
};

Register the listener after creation of navigation service.

const auto listener = tn::make_shared<GuidanceeObserver>();
navigationService->addGuidanceEventListener(listener);

Unregister it when not needed.

navigationService->removeGuidanceEventListener(listener);