Skip to content

Multiple Layer Detection

Multiple-layer detection (MLD)

This tutorial shows how to select map matched road from candidates for multiple-layered roads.

Get started

In the case of multiple-layered roads, such as elevated roads or multiple-layered urban roads, navigation service can identify which layer of the road the car is on.

Accumulate vehicle moved distance and altitude

To make multiple-layer detection work correctly, accumulated distance and altitude must be provided with a fine grained reference.

tn::drive::models::v1::VehicleLocation inputLocation;

// accumulated distance is calculated in the following way:
// let acc(D) = 0 at the beginning
// loop for each GPS location input:
//     acc(D) += distance(currentPosition, previousPosition)
// 
// currentPosition and previousPosition usually comes from the result of dead reckoning
// distance(currentPosition, previousPosition) =
//     sqrt((currentPosition.x - previousPosition.x) ^ 2 + (currentPosition.y - previousPosition.y) ^ 2)
inputLocation.cum_dist = getAccumulatedDistance();

// accumulated altitude is calculated in the following way:
// let acc(A) = 0 at the beginning
// loop for each GPS location input:
//     acc(A) += altitude(currentPosition, previousPosition)
//
// currentPosition and previousPosition usually comes from the result of dead reckoning
// altitude(currentPosition, previousPosition) = currentPosition.z - previousPosition.z
inputLocation.cum_alt = getAccumulatedAltitude();

navigationService->updateLocation(inputLocation);

Select candidate for multiple-layered roads with default search range

When there is no multiple-layer detection or multiple-layer detection fails to identify, it's possible to select another road candidate and make vehicle matched to it.

void LocationObserver::onPositionIndicatorUpdated(const tn::drive::models::v1::Indicator& indicator)
{
    // get all road candidates
    const auto& candidates = indicator.road_candidates;

    // select a candidate other than the first one which is the map matched result
    const auto result = navigationService->selectCandidate(candidates[1].id);
    if (result.isOK)
    {
        // candidates[1] is selected successfully
    }
    else
    {
        // candidates[1] cannot be selected due to it is neither in internal cache nor in the default search range around vehicle
    }
}

Select candidate for multiple-layered roads with customized search range

If the candidate road cannot be found in the internal cache, the navigation service will try to look it up in a specific range. The default search range is 50 meters around the vehicle. It can be adjusted to change the probability of finding a candidate successfully.

void LocationObserver::onPositionIndicatorUpdated(const tn::drive::models::v1::Indicator& indicator)
{
    // get all road candidates
    const auto& candidates = indicator.road_candidates;

    // select a candidate other than the first one which is the map matched result in a larger area
    const auto result = navigationService->selectCandidate(candidates[1].id, 100);
    if (result.isOK)
    {
        // candidates[1] is selected successfully
    }
    else
    {
        // candidates[1] cannot be selected due to it is neither in internal cache nor in the specified search range around vehicle
    }
}