lmw
2024-09-23 f23be5d1086538d541281b84d8b093f95c545c47
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package com.future.driver.base.gaode.gpsnav;
 
import android.os.Bundle;
import android.view.WindowManager;
 
import com.amap.api.navi.AMapNaviViewOptions;
import com.amap.api.navi.enums.NaviType;
import com.future.driver.R;
import com.future.driver.base.BaseEvent;
 
 
import org.greenrobot.eventbus.EventBus;
import org.greenrobot.eventbus.Subscribe;
 
public class GPSNaviActivity extends BaseGpsMapActivity {
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
        super.onCreate(savedInstanceState);
 
        setContentView(R.layout.activity_basic_navi);
        mAMapNaviView = findViewById(R.id.navi_view);
        mAMapNaviView.onCreate(savedInstanceState);
        mAMapNaviView.setAMapNaviViewListener(this);
 
        AMapNaviViewOptions options = new AMapNaviViewOptions();
        options.setScreenAlwaysBright(false);
        mAMapNaviView.setViewOptions(options);
 
        EventBus.getDefault().register(this);
    }
 
    @Override
    public void onInitNaviSuccess() {
        super.onInitNaviSuccess();
        /**
         *
         * 方法: int strategy=mAMapNavi.strategyConvert(congestion, avoidhightspeed, cost, hightspeed, multipleroute); 参数:
         *
         * @congestion 躲避拥堵
         * @avoidhightspeed 不走高速
         * @cost 避免收费
         * @hightspeed 高速优先
         * @multipleroute 多路径
         *
         *  说明: 以上参数都是boolean类型,其中multipleroute参数表示是否多条路线,如果为true则此策略会算出多条路线。
         *  注意: 不走高速与高速优先不能同时为true 高速优先与避免收费不能同时为true
         */
        int strategy = 0;
        try {
            //再次强调,最后一个参数为true时代表多路径,否则代表单路径
            strategy = mAMapNavi.strategyConvert(true, false, false, false, true);
        } catch (Exception e) {
            e.printStackTrace();
        }
//        mAMapNavi.setCarNumber("京", "DFZ588");
        mAMapNavi.calculateDriveRoute(sList, eList, mWayPointList, strategy);
 
    }
 
    @Override
    public void onCalculateRouteSuccess(int[] ids) {
        super.onCalculateRouteSuccess(ids);
        mAMapNavi.startNavi(NaviType.GPS);
//        mAMapNavi.startNavi(NaviType.EMULATOR);
 
    }
 
    @Subscribe
    public void exitNavi(BaseEvent e){
        if (e.getCode() == BaseEvent.EXIT_NAVI)
            finish();
    }
 
    @Override
    public void onArriveDestination() {
        super.onArriveDestination();
        finish();
    }
 
    @Override
    public void onEndEmulatorNavi() {
        super.onEndEmulatorNavi();
        finish();
    }
 
    @Override
    protected void onDestroy() {
        super.onDestroy();
        EventBus.getDefault().unregister(this);
    }
}