Document Navigation SDK for Android Guides Navigation Basics Basic Features

Basic Features

Prerequisites

Declare the navigation component Activity in your project's AndroidManifest.xml file:

<activity
    android:name="com.amap.api.navi.AmapRouteActivity"
    android:theme="@android:style/Theme.NoTitleBar"
    android:configChanges="orientation|keyboardHidden|screenSize|navigation" />

Start the Navigation Component Without Waypoints

Use the AmapNaviPage singleton to launch the navigation component:

// Build the navigation component configuration.
// No start point is provided, so the default start point is "My Location".
AmapNaviParams params = new AmapNaviParams(null, null, null, AmapNaviType.DRIVER, AmapPageType.ROUTE);

// Launch the navigation component.
AmapNaviPage.getInstance().showRouteActivity(getApplicationContext(), params, null);

Start the Navigation Component With Waypoints

Set the start point, waypoints (up to three), and end point to launch the navigation component. Each point can be described using latitude/longitude coordinates, a name, or an AMAP POI ID. The parameter rules are as follows:

1. Latitude and longitude coordinates are required.

2. Name is optional and is used only for display purposes. If set, the specified name is displayed; otherwise, default names such as "End Point" or "Waypoint 1" are used.

3. AMAP POI ID is optional but strongly recommended, as it helps reduce detours. When provided, the navigation component performs an exact POI search. The retrieved POI details are used for route calculation and override the provided latitude/longitude and name values.

4. If no start point is set, the user's current location is used as the start point and displayed as "My Location".

// Start point
Poi start = new Poi("Beijing Capital Airport", new LatLng(40.080525, 116.603039), "B000A28DAE");

// Waypoints
List<Poi> poiList = new ArrayList();
poiList.add(new Poi("Forbidden City", new LatLng(39.918058, 116.397026), "B000A8UIN8"));

// End point
Poi end = new Poi("Peking University", new LatLng(39.941823, 116.426319), "B000A816R6");

// Component parameter configuration
AmapNaviParams params = new AmapNaviParams(start, poiList, end, AmapNaviType.DRIVER, AmapPageType.ROUTE);

// Launch the component
AmapNaviPage.getInstance().showRouteActivity(getApplicationContext(), params, null);

Exit the Navigation Component

After the navigation component is launched, users can tap the back button in the upper-left corner of the route planning page to exit. Developers can also programmatically exit the component using the following method:

// Exit the navigation component
AmapNaviPage.getInstance().exitRouteActivity();

Navigation Component Callback Methods

The INaviInfoCallback interface provides a series of callback methods. To use them, implement the interface and pass the callback instance as the last parameter of the showRouteActivity() method.

Note: When using the navigation component, you can still register navigation callbacks via AMapNavi to listen for additional navigation information.

/**
 * Callback for navigation voice announcements.
 *
 * @param s The announcement text.
 * @since 5.2.0
 */
void onGetNavigationText(String s);

/**
 * Callback when the GPS location is updated.
 *
 * @param location The current location information.
 * @since 5.2.0
 */
void onLocationChange(AMapNaviLocation location);

/**
 * Callback when exiting the component or component navigation.
 *
 * @param pageType See {@link com.amap.api.navi.enums.PageType}.
 * @since 5.6.0
 */
void onExitPage(int pageType);

/**
 * Callback when the route planning preference is changed on the strategy selection screen.
 *
 * @param strategy The new preference. See {@link com.amap.api.navi.enums.PathPlanningStrategy}.
 * @since 6.0.0
 */
void onStrategyChanged(int strategy);

/**
 * Returns a custom View placed at the bottom of the navigation map interface.
 * This View is positioned below the main navigation UI. Ensure you call
 * setLayoutParams() and set an appropriate height. Leave enough space for
 * navigation controls to avoid overlap or compression.
 *
 * @return View
 * @since 6.1.0
 */
View getCustomNaviBottomView();

/**
 * Returns a custom View placed at the current road name position on the
 * navigation map interface. When this method is used, the current road name
 * is not displayed.
 *
 * @return View
 * @since 6.1.0
 */
View getCustomNaviView();

/**
 * Callback when the map's day/night mode changes.
 *
 * @param mapType Map type. See AMap class for reference. 3 = night, 4 = day.
 * @since 6.7.0
 */
void onMapTypeChanged(int mapType);

/**
 * Returns a custom View placed at the vertical center and horizontal left
 * position on the navigation map interface.
 *
 * @return View
 * @since 6.9.0
 */
View getCustomMiddleView();

/**
 * Callback when the navigation perspective changes.
 *
 * @param naviMode Navigation perspective. 1 = north-up, 2 = heading-up.
 * @since 7.1.0
 */
void onNaviDirectionChanged(int naviMode);

/**
 * Callback when the day/night mode setting changes.
 *
 * @param mode 0 = auto switch, 1 = day, 2 = night.
 * @since 7.1.0
 */
void onDayAndNightModeChanged(int mode);

/**
 * Callback when the broadcast mode changes.
 *
 * @param mode 1 = concise, 2 = detailed, 3 = silent.
 * @since 7.1.0
 */
void onBroadcastModeChanged(int mode);

/**
 * Callback when the auto scale setting changes.
 *
 * @param enable Whether auto scale is enabled.
 * @since 7.1.0
 */
void onScaleAutoChanged(boolean enable);