Document Navigation SDK for Android Guides Route Planning Headless Routing

Headless Routing

Overview

Independent route planning allows you to calculate a route without automatically applying the result to the current navigation session or interfering with ongoing navigation. You must manually call the API to pass the route planning result and start navigation. This feature is ideal for scenarios where you need to preview a route without disrupting the current navigation, such as route previews.

Independent route planning supports the following transportation modes:

- Driving

- Cycling

- Walking

The following route planning methods are supported:

Route planning without a start point: Leave the start coordinate empty when planning a route.

Route planning with coordinates: Pass only latitude and longitude for the start and end points in NaviPoi.

Route planning with POI: Pass a POI ID to improve route planning accuracy.

Key Interfaces

To implement independent route planning, you need to understand the following interfaces.

1. Calculate an Independent Route

The interface for calculating an independent route for driving,  cycling, or walking is located in AMapNavi.

/**
 * Calculates an independent route using POI information.
 *
 * @param fromPoi       The start point.
 * @param toPoi         The end point.
 * @param wayPoints     A list of waypoints.
 * @param strategy      The route planning strategy. For driving, see
 *                      {@link com.amap.api.navi.enums.PathPlanningStrategy}.
 *                      For cycling and walking, see {@link TravelStrategy}.
 * @param transportType The transportation type: 1 for driving, 2 for cycling,
 *                      3 for walking.
 * @param observer      The callback listener for the route planning result.
 * @return {@code true} if the request was successfully submitted,
 *         {@code false} otherwise.
 * @since 7.7.0
 */
public boolean independentCalculateRoute(NaviPoi fromPoi, NaviPoi toPoi,
        List<NaviPoi> wayPoints, int strategy, int transportType,
        AMapNaviIndependentRouteListener observer)

2. Route Planning Callback

Similar to standard route planning, independent route planning requires a callback listener to receive the result. The AMapNaviIndependentRouteListener interface is passed as the last parameter when calling the independent route planning method.

The AMapNaviIndependentRouteListener interface contains two callbacks:

/**
 * Callback invoked when the independent route calculation succeeds.
 *
 * @param group The route planning result, represented as a route group.
 * @since 7.7.0
 */
void onIndependentCalculateSuccess(AMapNaviPathGroup group);

/**
 * Callback invoked when the independent route calculation fails.
 *
 * @param routeResult The failure information.
 * @since 7.7.0
 */
void onIndependentCalculateFail(AMapCalcRouteResult routeResult);

3. Route Planning Result

When the route calculation succeeds, the callback returns an AMapNaviPathGroup object. This object represents a collection of routes. It stores the current routes and allows you to reorder them, enabling route selection before navigation begins.

The core methods of AMapNaviPathGroup are as follows:

/**
 * Returns the main route.
 *
 * @return The main route.
 * @since 7.7.0
 */
public AMapNaviPath getMainPath()

/**
 * Returns the index of the main route.
 *
 * @return The index of the main route.
 * @since 7.7.0
 */
public int getMainPathIndex()

/**
 * Returns the route at the specified index.
 *
 * @param index The index of the route.
 * @return The route at the given index.
 * @since 7.7.0
 */
public AMapNaviPath getPath(int index)

/**
 * Returns the number of routes in the route group.
 *
 * @return The number of routes.
 * @since 7.7.0
 */
public int getPathCount()

/**
 * Selects the main route before navigation starts.
 *
 * @param routeId The route ID of the main route. The first route has ID 12,
 *                the second has ID 13, and the third has ID 14.
 * @return {@code true} if the selection was successful, {@code false} otherwise.
 * @since 7.7.0
 */
public boolean selectRouteWithIndex(int routeId)

4. Start Navigation with an Independent Route

The route result from independent route planning can be used for route preview or to start navigation. The interface for starting navigation is located in AMapNavi.

/**
 * Starts navigation using the specified route.
 *
 * @param naviType  The navigation type. See
 *                  {@link com.amap.api.navi.enums.NaviType}.
 * @param pathGroup The route group.
 * @return {@code true} if navigation started successfully, {@code false} otherwise.
 * @since 7.7.0
 */
public boolean startNaviWithPath(int naviType, AMapNaviPathGroup pathGroup)

Important: After starting navigation with an independent route, the route returned by AMapNavi.getNaviPath() switches to the independent route. The previous route is automatically cleared. The independent route becomes invalid after the navigation session is destroyed. It cannot be saved externally, and you cannot use a previously saved independent route to start navigation.