您当前的位置: Android导航SDK > 开发指南 > 诱导信息获取
诱导信息获取

简介

导航SDK3.3.0开始,对外提供诱导信息获取的接口,满足用户对诱导信息获取的需求。支持的消息类型请参考链接

使用

1.定义诱导回调接口。开发者需要新建如下的接口,以便在该接口的回调中处理信息。

BaiduNaviManager.NavEventListener eventListerner = new BaiduNaviManager.NavEventListener() {
 
        @Override
        public void onCommonEventCall(int what, int arg1, int arg2, Bundle bundle) {
            BNEventHandler.getInstance().handleNaviEvent(what, arg1, arg2, bundle);
        }
    };

2.发起导航时,传入该接口。

BaiduNaviManager.getInstance().launchNavigator(this, list, 1, true, new DemoRoutePlanListener(sNode),
                    eventListerner);

3. 处理回调回来的信息。导航SDK提供了放大图、路线规划等消息的回调通知,开发者可以通过该接口的来获取信息。参考Demon的方式:

public void handleNaviEvent(int what, int arg1, int arg2, Bundle bundle) {
        Log.i("onCommonEventCall", String.format("%d,%d,%d,%s", what, arg1, arg2,
                (bundle == null ? "" : bundle.toString())));
        switch (what) {
            case BNaviCommonParams.MessageType.EVENT_NAVIGATING_STATE_BEGIN:
                break;
            case BNaviCommonParams.MessageType.EVENT_NAVIGATING_STATE_END:
                break;
            case BNaviCommonParams.MessageType.EVENT_GPS_LOCATED:
                mEventDialog.updateLocateState(true);
                break;
            case BNaviCommonParams.MessageType.EVENT_GPS_DISMISS:
                mEventDialog.updateLocateState(false);
                break;
            case BNaviCommonParams.MessageType.EVENT_ON_YAW_SUCCESS:
                break;
            case BNaviCommonParams.MessageType.EVENT_ROAD_TURN_ICON_UPDATE:
                byte[] byteArray = bundle.getByteArray(BNaviCommonParams.BNGuideKey.ROAD_TURN_ICON);
                Bitmap map = BitmapFactory.decodeByteArray(byteArray, 0, byteArray.length);
                mEventDialog.updateTurnIcon(map);
                break;
            case BNaviCommonParams.MessageType.EVENT_ROAD_TURN_DISTANCE_UPDATE:
                String turndis = bundle.getString(BNaviCommonParams.BNGuideKey.TROAD_TURN_DISTANCE);
                mEventDialog.updateGoDistanceTx(turndis);
                mEventDialog.updateAlongMeters(turndis);
                break;
            case BNaviCommonParams.MessageType.EVENT_ROAD_NEXT_ROAD_NAME:
                String nextRoad = bundle.getString(BNaviCommonParams.BNGuideKey.NEXT_ROAD_NAME);
                if (!TextUtils.isEmpty(nextRoad)) {
                    mEventDialog.updateNextRoad(nextRoad); 
                }
                break;
            case BNaviCommonParams.MessageType.EVENT_ROAD_CURRENT_ROAD_NAME:
                String currentRoad = bundle.getString(BNaviCommonParams.BNGuideKey.CURRENT_ROAD_NAME);
                if (!TextUtils.isEmpty(currentRoad)) {
                    mEventDialog.updateCurrentRoad(currentRoad);
                }
                break;
            case BNaviCommonParams.MessageType.EVENT_REMAIN_DISTANCE_UPDATE:
                String remainDisctance = bundle.getString(BNaviCommonParams.BNGuideKey.TOTAL_REMAIN_DISTANCE);
                mEventDialog.updateRemainDistance(remainDisctance);
                break;
            case BNaviCommonParams.MessageType.EVENT_REMAIN_TIME_UPDATE:
                String remainTime = bundle.getString(BNaviCommonParams.BNGuideKey.TOTAL_REMAIN_TIME);
                mEventDialog.updateRemainTime(remainTime);
                break;
            case BNaviCommonParams.MessageType.EVENT_RASTER_MAP_SHOW:
                int type = bundle.getInt(BNaviCommonParams.BNEnlargeRoadKey.ENLARGE_TYPE);
                byte[] arrowByte = bundle.getByteArray(BNaviCommonParams.BNEnlargeRoadKey.ARROW_IMAGE);
                byte[] bgByte = bundle.getByteArray(BNaviCommonParams.BNEnlargeRoadKey.BACKGROUND_IMAGE);
                Bitmap arrowMap = BitmapFactory.decodeByteArray(arrowByte, 0, arrowByte.length);
                Bitmap bgMap = BitmapFactory.decodeByteArray(bgByte, 0, bgByte.length);
                mEventDialog.onEnlageShow(type, arrowMap, bgMap);
                break;
            case BNaviCommonParams.MessageType.EVENT_RASTER_MAP_UPDATE:
                String remainDistance = bundle.getString(BNaviCommonParams.BNEnlargeRoadKey.REMAIN_DISTANCE);
                String roadName = bundle.getString(BNaviCommonParams.BNEnlargeRoadKey.ROAD_NAME);
                int progress = bundle.getInt(BNaviCommonParams.BNEnlargeRoadKey.DRIVE_PROGRESS);
                break;
            case BNaviCommonParams.MessageType.EVENT_RASTER_MAP_HIDE:
                mEventDialog.onEnlargeHide();
                break;
            case BNaviCommonParams.MessageType.EVENT_ROUTE_PLAN_SUCCESS:
                int distance = bundle.getInt(BNaviCommonParams.BNRouteInfoKey.TOTAL_DISTANCE);
                int time = bundle.getInt(BNaviCommonParams.BNRouteInfoKey.TOTAL_TIME);
                int tollFees = bundle.getInt(BNaviCommonParams.BNRouteInfoKey.TOLL_FESS);
                int lightCounts = bundle.getInt(BNaviCommonParams.BNRouteInfoKey.TRAFFIC_LIGHT);
                int gasMoney = bundle.getInt(BNaviCommonParams.BNRouteInfoKey.GAS_MONEY);
                break;
            case BNaviCommonParams.MessageType.EVENT_SERVICE_AREA_UPDATE:
                String firstName = bundle.getString(BNaviCommonParams.BNGuideKey.FIRST_SERVICE_NAME);
                int firstDistance = bundle.getInt(BNaviCommonParams.BNGuideKey.FIRST_SERVICE_TIME);
                String secondeName = bundle.getString(BNaviCommonParams.BNGuideKey.SECOND_SERVICE_NAME);
                int secondeDistance = bundle.getInt(BNaviCommonParams.BNGuideKey.SECOND_SERVICE_TIME);
                break;
            case BNaviCommonParams.MessageType.EVENT_CURRENT_SPEED:
                mEventDialog.updateCurrentSpeed(String.valueOf(arg1));
                break;
            case BNaviCommonParams.MessageType.EVENT_ALONG_UPDATE:
                boolean isAlong = bundle.getBoolean(BNaviCommonParams.BNGuideKey.IS_ALONG);
                break;
            case BNaviCommonParams.MessageType.EVENT_CURRENT_MILES:
                int miles = arg1;
            default :
                break;
        }

详细的使用方式,可以参考官方的Demon工程,里面有诱导信息的详细使用。