Navigation Events
Overview
During real driving navigation, the Navigation SDK exposes navigation information and data in real time through listeners such as AMapNaviListener, ParallelRoadListener, and AimlessModeListener. This enables custom UI development and provides solutions for HUD and smart hardware. Cycling and walking navigation follow the same pattern as driving, using AMapNaviListener to receive navigation events and data.
Register for General Navigation Events and Data (Driving, Cycling, Walking)
AMapNavi mAMapNavi = AMapNavi.getInstance(mContext);
// 1. Register for general navigation events and data
mAMapNavi.addAMapNaviListener(new AMapNaviListener() {
// Called when the navigation manager is initialized successfully
@Override
public void onInitNaviSuccess() {
}
// Called when navigation starts
@Override
public void onStartNavi(int type) {
}
...
});Register for Parallel Road Data (Driving)
AMapNavi mAMapNavi = AMapNavi.getInstance(mContext);
// Register for parallel road data
mAMapNavi.addParallelRoadListener(new ParallelRoadListener() {
// Called when parallel road information changes
@Override
public void notifyParallelRoad(AMapNaviParallelRoadStatus roadStatus) {
}
});Register for Aimless Mode Data (Driving)
AMapNavi mAMapNavi = AMapNavi.getInstance(mContext);
// Register for aimless mode data
mAMapNavi.addAimlessModeListener(new AimlessModeListener() {
// Called when traffic facility information is updated in aimless mode
@Override
public void onUpdateTrafficFacility(AMapNaviTrafficFacilityInfo[] infos) {
}
// Called when electronic eye camera information is updated in aimless mode
@Override
public void onUpdateAimlessModeElecCameraInfo(AMapNaviTrafficFacilityInfo[] cameraInfo) {
}
// Called when aimless mode statistics are updated
@Override
public void updateAimlessModeStatistics(AimLessModeStat aimLessModeStat) {
}
// Called when congestion information is updated in aimless mode
@Override
public void updateAimlessModeCongestionInfo(AimLessModeCongestionInfo aimLessModeCongestionInfo) {
}
});NaviInfo
NaviInfo contains navigation information such as the current road name, remaining time and distance to the destination, and facility information that has not been avoided. You can obtain a NaviInfo object through the onNaviInfoUpdate callback in AMapNaviListener. The custom navigation view AMapNaviView, as well as the information displayed in the top guidance panel and bottom panel of the navigation component, is primarily obtained from this callback.
/**
* Callback for navigation guidance information.
*
* @param naviInfo The navigation information object.
*/
void onNaviInfoUpdate(NaviInfo naviInfo);
Junction View
Junction view includes two callbacks for showing and hiding, and is further divided into two types based on whether the view is a real-scene image or a model image. This results in a total of four callbacks, all located in AMapNaviListener. These are only valid for driving navigation.
/**
* Callback for showing the junction view (real-scene image).
*
* @param aMapNaviCross The junction view class, from which you can obtain the junction view bitmap.
* @since 1.5.0
*/
void showCross(AMapNaviCross aMapNaviCross);
/**
* Callback for hiding the junction view (real-scene image).
*
* @since 1.5.0
*/
void hideCross();
/**
* Callback for showing the junction view (model image).
*
* @param modelCross The model view data class, from which you can obtain vector data needed to draw the model view.
* @since 5.0.0
*/
void showModeCross(AMapModelCross modelCross);
/**
* Callback for hiding the junction view (model image).
*
* @since 5.0.0
*/
void hideModeCross();
Lane Information
Lane information includes two callbacks for showing and hiding, located in AMapNaviListener.
/**
* Callback for showing lane information.
*
* @param laneInfo Lane information, providing current road information. Can be used to fully customize the display using your own assets.
* @since 6.0.0
*/
void showLaneInfo(AMapLaneInfo laneInfo);
/**
* Callback for hiding lane information.
*
* @since 1.5.0
*/
void hideLaneInfo();
Turn Icon
Turn icon information at intersections during navigation can be obtained from NaviInfo. The method for obtaining NaviInfo is described above. NaviInfo provides two interfaces related to turn icons: one to directly obtain the turn icon bitmap, and another to obtain the turn icon type enum, which can be used for custom turn icon drawing. The icon bitmap includes road network information and is more intuitive.
Interfaces in NaviInfo:
/**
* Gets the turn icon bitmap. May return null. If null is returned, use getIconType to fill the icon.
*
* @return The turn icon bitmap.
* @since 6.4.0
*/
public Bitmap getIconBitmap();
/**
* Gets the navigation turn icon type enum.
*
* @return The turn icon enum. See {@link com.amap.api.navi.enums.IconType} for details.
*/
public int getIconType();
Traffic Information
There are two interfaces for traffic information. One is an active interface, getTrafficStatuses in the route class AMapNaviPath, which returns the current real-time traffic status of the route and can be used to draw a light bar chart. The other is a passive callback, onTrafficStatusUpdate in AMapNaviListener, which is triggered when the traffic status on the route changes.
Active interface in AMapNaviPath:
/**
* Gets the traffic status information for the current route.
*
* @return A list of traffic status objects.
*/
public List<AMapTrafficStatus> getTrafficStatuses();Passive interface in AMapNaviListener:
/**
* Callback when the traffic status information for the route is updated.
*/
void onTrafficStatusUpdate();
Note: To obtain more real-time and accurate traffic information, it is recommended to set up an AMapNaviListener. After receiving the onTrafficStatusUpdate callback, use AMapNavi's getNaviPath or getNaviPaths interface to get the latest route object, and then use the route object's getTrafficStatuses interface to get the real-time traffic status.
Camera Information
Camera information includes the camera type, whether there is a speed limit, latitude and longitude coordinates, and the distance from the current vehicle position to the camera. This information is available in AMapNaviListener.
/**
* Callback function for camera information during navigation.
*
* @param infoArray An array of camera information objects.
* @since 5.0.0
*/
void updateCameraInfo(AMapNaviCameraInfo[] infoArray);
Average Speed Check Camera Information
Starting from SDK v6.0.0, the Navigation SDK exposes average speed check camera information. This includes the positional relationship between the vehicle and the average speed check section, as well as some dynamically updated real-time information.
/**
* Callback for average speed check camera information during navigation.
*
* @param startCameraInfo The start point information of the average speed check section.
* @param endCameraInfo The end point information of the average speed check section.
* @param status See {@link com.amap.api.navi.enums.CarEnterCameraStatus} for specific types.
* @since 6.0.0
*/
void updateIntervalCameraInfo(AMapNaviCameraInfo startCameraInfo, AMapNaviCameraInfo endCameraInfo, int status);
Service Area and Toll Station Information
Starting from SDK v5.0.0, the Navigation SDK exposes service area and toll station information. This includes the service area type, name, latitude and longitude coordinates, and the distance from the current vehicle position to the service area. This information can be used for custom information display.
/**
* Callback for service area information.
*
* @param infoArray An array of service area objects. See the AMapServiceAreaInfo class for details.
* @since 5.0.0
*/
void onServiceAreaUpdate(AMapServiceAreaInfo[] infoArray);Traffic Events
Starting from SDK v6.2.0, the Navigation SDK provides the ability to expose traffic event information on the route. This includes avoidance notifications for congested areas, restricted areas, no-entry areas, and road closures. It also provides a notification for weak GPS signals. The event notification type can be obtained using the getNotifyType method of AMapNaviRouteNotifyData.
/**
* Notification for road information during navigation.
*
* <p>
* Provides avoidance notifications during navigation for situations such as
* congested areas, restricted areas, no-entry areas, and road closures.<br/>
* Notification and avoidance information can be obtained via
* {@link com.amap.api.navi.model.AMapNaviRouteNotifyData}.
* </p>
*
* @param notifyData The notification and avoidance information. See
* {@link com.amap.api.navi.model.AMapNaviRouteNotifyData} for details.
* @since 6.2.0
*/
void onNaviRouteNotify(AMapNaviRouteNotifyData notifyData);