Document Navigation SDK for Android Guides Turn-by-Turn Navigation Real-Time and Simulated Navigation

Real-Time and Simulated Navigation

Real-time navigation uses continuous positioning data to drive the navigation experience and is used during actual navigation. You must successfully calculate a route before starting navigation.

Initialize Navigation and Register Callbacks

Create an AMapNavi navigation object and register a listener to receive navigation events.

/**
 * Creates an AMapNavi navigation object.
 *
 * @param context The corresponding Context
 * @return The navigation object (singleton).
 */
public synchronized static AMapNavi getInstance(Context context)
     
/**
 * Adds a navigation event callback listener.
 *
 * @param naviListener The navigation callback listener
 * @since 1.7.0
 */
@Override
public void addAMapNaviListener(AMapNaviListener naviListener)

Calculate a Route

Use the following method to calculate a driving route based on POI (Point of Interest) information. This method avoids detours caused by arrival point issues and navigates to multiple exits for POIs such as subway stations.

Note: In the NaviPoi object, the POI ID is used for route calculation first. If that fails, the latitude and longitude are used instead.

/**
 * Calculates a driving route using POI information.
 * <p>
 * This method can avoid detours caused by arrival point issues. For POIs with multiple exits,
 * such as subway stations, it will navigate to each exit.
 * Note: In the NaviPoi object, the POI ID is used for route calculation first.
 * If that fails, the latitude and longitude are used instead.
 * </p>
 *
 * @param fromPoi   The starting POI {@link com.amap.api.navi.model.NaviPoi}. If an invalid start POI is provided, the current location is used.
 * @param toPoi     The destination POI {@link com.amap.api.navi.model.NaviPoi}
 * @param wayPoints A list of waypoint POIs {@link com.amap.api.navi.model.NaviPoi}
 * @param strategy  The navigation strategy {@link com.amap.api.navi.enums.PathPlanningStrategy}
 * @return Whether the route calculation was successfully initiated
 * @since 6.6.0
 */
@Override
public boolean calculateDriveRoute(NaviPoi fromPoi, NaviPoi toPoi, List<NaviPoi> wayPoints, int strategy)

Handle Route Calculation Callbacks

Implement the following callbacks to handle the result of a route calculation. These callbacks are triggered for initial route calculation, rerouting due to off-route deviation, user strategy changes, or itinerary point changes.

/**
 * Callback for a successful route calculation. This includes initial route calculation,
 * rerouting due to off-route deviation, user strategy changes, or itinerary point changes.
 * The specific route calculation result can be obtained via {@link com.amap.api.navi.model.AMapCalcRouteResult}.
 * Use CalcRouteResult to get the error code, calculation type, and route ID.
 *
 * @param routeResult {@link com.amap.api.navi.model.AMapCalcRouteResult}
 * @since 6.1.0
 */
void onCalculateRouteSuccess(AMapCalcRouteResult routeResult);

/**
 * Callback for a failed route calculation. This includes initial route calculation,
 * rerouting due to off-route deviation, user strategy changes, or itinerary point changes.
 * The specific route calculation result can be obtained via {@link com.amap.api.navi.model.AMapCalcRouteResult}.
 * Use CalcRouteResult to get the error code, calculation type, and route ID.
 *
 * @param routeResult {@link com.amap.api.navi.model.AMapCalcRouteResult}
 * @since 6.1.0
 */
void onCalculateRouteFailure(AMapCalcRouteResult routeResult);

Start Navigation After Route Calculation

After a successful route calculation, start navigation. Real-time navigation automatically enables the device's satellite positioning. Simulated navigation does not require positioning.

/**
 * Starts navigation.
 *
 * @param naviType The navigation type. 1: Real-time navigation, 2: Simulated navigation.
 * @return Whether the navigation started successfully. true: success, false: failure.
 */
@Override
public boolean startNavi(int naviType);