Quellcode durchsuchen

路径规划修改

huyuguo vor 4 Jahren
Ursprung
Commit
00ed8e72ac

+ 1 - 0
app/src/main/java/com/electric/chargingpile/activity/RecommendZhanActivity.java

@ -125,6 +125,7 @@ public class RecommendZhanActivity extends Activity implements View.OnClickListe
125 125
        if (aMap == null) {
126 126
            aMap = mapView.getMap();
127 127
            Util.setMapCustomStyleFile(aMap, getApplicationContext());
128
            aMap.getUiSettings().setGestureScaleByMapCenter(true);
128 129
            maxZoomLevel = aMap.getMaxZoomLevel();
129 130
            minZoomLevel = aMap.getMinZoomLevel();
130 131
            MyLocationStyle myLocationStyle = new MyLocationStyle();

+ 9 - 7
app/src/main/java/com/electric/chargingpile/activity/RoutePlanMapActivity.java

@ -12,6 +12,7 @@ import android.database.sqlite.SQLiteDatabase;
12 12
import android.database.sqlite.SQLiteDatabaseLockedException;
13 13
import android.database.sqlite.SQLiteException;
14 14
import android.graphics.Bitmap;
15
import android.graphics.BitmapFactory;
15 16
import android.graphics.Canvas;
16 17
import android.graphics.Matrix;
17 18
import android.graphics.drawable.BitmapDrawable;
@ -155,9 +156,9 @@ public class RoutePlanMapActivity extends Activity implements LocationSource, AM
155 156
    NaviLatLng endLatlng;
156 157
    NaviLatLng startLatlng;
157 158
    NaviLatLng zhongLatlng;
158
    List<NaviLatLng> startList = new ArrayList<NaviLatLng>();
159
    List<NaviLatLng> endList = new ArrayList<NaviLatLng>();
160
    List<NaviLatLng> zhongList = new ArrayList<NaviLatLng>();
159
    public static List<NaviLatLng> startList = new ArrayList<NaviLatLng>();
160
    public static List<NaviLatLng> endList = new ArrayList<NaviLatLng>();
161
    public static List<NaviLatLng> zhongList = new ArrayList<NaviLatLng>();
161 162
    private MapView mapView;
162 163
    private AMap amap;
163 164
    private AMapNavi aMapNavi;
@ -2055,14 +2056,15 @@ public class RoutePlanMapActivity extends Activity implements LocationSource, AM
2055 2056
                            AMapNaviPath path = (aMapNavi.getNaviPaths()).get(routeIds[i]);
2056 2057
                            //你可以通过这个AMapNaviPath生成一个RouteOverLay用于加在地图上
2057 2058
                            routeOverLay = new RouteOverLay(amap, path, this);
2058
                            routeOverLay.setStartPointBitmap(drawableToBitamp(getResources().getDrawable(R.drawable.icon_newstarr)));
2059
                            routeOverLay.setEndPointBitmap(drawableToBitamp(getResources().getDrawable(R.drawable.icon_newstopr)));
2060
                            routeOverLay.setWayPointBitmap(drawableToBitamp(getResources().getDrawable(R.drawable.icon_zhanwei)));
2059
                            routeOverLay.setStartPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.icon_newstarr));
2060
                            routeOverLay.setEndPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.icon_newstopr));
2061
                            routeOverLay.setWayPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.icon_zhanwei));
2061 2062
                            routeOverLay.setTrafficLightsVisible(false);
2062
                            routeOverLay.addToMap();
2063 2063
                            routeOverlays.put(routeIds[i], routeOverLay);
2064
                            routeOverLay.addToMap();
2064 2065
                        }
2065 2066
2067
2066 2068
                        if (!calculateSuccess) {
2067 2069
                            Toast.makeText(this, "请先算路", Toast.LENGTH_SHORT).show();
2068 2070
                            return;

+ 37 - 74
app/src/main/java/com/electric/chargingpile/activity/SimpleNaviActivity.java

@ -1,12 +1,16 @@
1 1
package com.electric.chargingpile.activity;
2 2
3 3
import android.app.Activity;
4
import android.graphics.BitmapFactory;
4 5
import android.os.Build;
5 6
import android.os.Bundle;
6 7
import android.util.Log;
7 8
import android.view.Window;
8 9
import android.view.WindowManager;
9 10
11
import com.amap.api.navi.AMapNaviViewOptions;
12
import com.amap.api.navi.model.NaviLatLng;
13
import com.amap.api.navi.view.RouteOverLay;
10 14
import com.amap.api.navi.AMapNavi;
11 15
import com.amap.api.navi.AMapNaviListener;
12 16
import com.amap.api.navi.AMapNaviView;
@ -19,6 +23,7 @@ import com.amap.api.navi.model.AMapNaviCameraInfo;
19 23
import com.amap.api.navi.model.AMapNaviCross;
20 24
import com.amap.api.navi.model.AMapNaviInfo;
21 25
import com.amap.api.navi.model.AMapNaviLocation;
26
import com.amap.api.navi.model.AMapNaviPath;
22 27
import com.amap.api.navi.model.AMapNaviRouteNotifyData;
23 28
import com.amap.api.navi.model.AMapNaviTrafficFacilityInfo;
24 29
import com.amap.api.navi.model.AMapServiceAreaInfo;
@ -28,6 +33,8 @@ import com.amap.api.navi.model.NaviInfo;
28 33
import com.autonavi.tbt.TrafficFacilityInfo;
29 34
import com.electric.chargingpile.R;
30 35
36
import java.util.List;
37
31 38
/**
32 39
 * 创建时间:15/12/7 18:35
33 40
 * 项目名称:newNaviDemo
@ -44,6 +51,7 @@ public class SimpleNaviActivity extends Activity implements AMapNaviListener, AM
44 51
    //    private TTSController mTtsManager;
45 52
    private AMapNaviViewListener aMapNaviViewListener;
46 53
    private boolean isGps;
54
    private RouteOverLay routeOverLay;
47 55
48 56
49 57
    @Override
@ -52,28 +60,33 @@ public class SimpleNaviActivity extends Activity implements AMapNaviListener, AM
52 60
53 61
        setContentView(R.layout.activity_simple_navi);
54 62
        setStatusBarColor(SimpleNaviActivity.this, R.color.black);
55
//        initData();
56 63
        mAMapNaviView = (AMapNaviView) findViewById(R.id.navi_view);
57 64
        mAMapNaviView.onCreate(savedInstanceState);
58 65
        mAMapNaviView.setAMapNaviViewListener(this);
59 66
60 67
61
//        mTtsManager = TTSController.getInstance(getApplicationContext());
62
//        mTtsManager.startSpeaking();
68
        AMapNaviViewOptions options = mAMapNaviView.getViewOptions();
69
        options.setAutoDrawRoute(false);
70
        options.setAfterRouteAutoGray(true);
71
        mAMapNaviView.setViewOptions(options);
63 72
64 73
        mAMapNavi = AMapNavi.getInstance(getApplicationContext());
65 74
        mAMapNavi.addAMapNaviListener(this);
66
//        mAMapNavi.addAMapNaviListener(mTtsManager);
67
68 75
        mAMapNavi.setEmulatorNaviSpeed(60);
69 76
        mAMapNavi.setUseInnerVoice(true);
70 77
78
71 79
        isGps = getIntent().getBooleanExtra("gps", false);
80
81
        mAMapNavi.calculateDriveRoute(RoutePlanMapActivity.startList, RoutePlanMapActivity.endList, RoutePlanMapActivity.zhongList, 10);
82
83
72 84
        if (isGps)
73 85
            mAMapNavi.startNavi(NaviType.GPS);
74 86
        else {
75 87
            mAMapNavi.startNavi(NaviType.EMULATOR);
76 88
        }
89
77 90
    }
78 91
79 92
    public static void setStatusBarColor(Activity activity, int colorId) {
@ -83,22 +96,8 @@ public class SimpleNaviActivity extends Activity implements AMapNaviListener, AM
83 96
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
84 97
            window.setStatusBarColor(activity.getResources().getColor(colorId));
85 98
        } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
86
            //使用SystemBarTint库使4.4版本状态栏变色,需要先将状态栏设置为透明
87
//            transparencyBar(activity);
88
////            SystemBarTintManager tintManager = new SystemBarTintManager(activity);
89
////            tintManager.setStatusBarTintEnabled(true);
90
////            tintManager.setStatusBarTintResource(colorId);
91 99
        }
92 100
    }
93
//    private void initData(){
94
//        zhong_one = getIntent().getStringExtra("zhong_one");
95
//        zhong_two = getIntent().getStringExtra("zhong_two");
96
//        zhong_three = getIntent().getStringExtra("zhong_three");
97
//        Log.e("zhong_one",zhong_one);
98
//        Log.e("zhong_two",zhong_two);
99
//        Log.e("zhong_three",zhong_three);
100
//
101
//    }
102 101
103 102
    @Override
104 103
    protected void onResume() {
@ -110,12 +109,6 @@ public class SimpleNaviActivity extends Activity implements AMapNaviListener, AM
110 109
    protected void onPause() {
111 110
        super.onPause();
112 111
        mAMapNaviView.onPause();
113
//        mTtsManager.playText("高德地图持续为您导航");
114
115
116
//        mTtsManager.stopSpeaking();
117
//        停止导航之后,会触及底层stop,然后就不会再有回调了,但是讯飞当前还是没有说完的半句话还是会说完
118
//        mAMapNavi.stopNavi();
119 112
    }
120 113
121 114
    @Override
@ -123,7 +116,6 @@ public class SimpleNaviActivity extends Activity implements AMapNaviListener, AM
123 116
        super.onDestroy();
124 117
        mAMapNaviView.onDestroy();
125 118
        mAMapNavi.stopNavi();
126
//        mTtsManager.destroy();
127 119
    }
128 120
129 121
@ -149,20 +141,19 @@ public class SimpleNaviActivity extends Activity implements AMapNaviListener, AM
149 141
150 142
    @Override
151 143
    public void onLocationChange(AMapNaviLocation aMapNaviLocation) {
152
        Log.e("onLocationChange", "---");
144
        try {
145
            routeOverLay.updatePolyline(aMapNaviLocation);
146
        } catch (Exception e) {
147
            e.printStackTrace();
148
        }
153 149
    }
154 150
155 151
    @Override
156 152
    public void onGetNavigationText(int i, String s) {
157
//        Toast.makeText(getApplicationContext(),s,Toast.LENGTH_SHORT).show();
158
//        mTtsManager.playText(s);
159
160
161 153
    }
162 154
163 155
    @Override
164 156
    public void onGetNavigationText(String s) {
165
//        mTtsManager.playText(s);
166 157
    }
167 158
168 159
    @Override
@ -172,158 +163,138 @@ public class SimpleNaviActivity extends Activity implements AMapNaviListener, AM
172 163
173 164
    @Override
174 165
    public void onArriveDestination() {
175
        Log.e("onArriveDestination", "---");
176
177 166
    }
178 167
179 168
180 169
    @Override
181 170
    public void onCalculateRouteFailure(int i) {
182
183 171
    }
184 172
185 173
    @Override
186 174
    public void onReCalculateRouteForYaw() {
187
188 175
    }
189 176
190 177
    @Override
191 178
    public void onReCalculateRouteForTrafficJam() {
192
193 179
    }
194 180
195 181
    @Override
196 182
    public void onArrivedWayPoint(int i) {
197
198
199 183
    }
200 184
201 185
    @Override
202 186
    public void onGpsOpenStatus(boolean b) {
203
204 187
    }
205 188
206 189
    @Override
207 190
    public void onNaviInfoUpdated(AMapNaviInfo aMapNaviInfo) {
208
209 191
    }
210 192
211 193
    @Override
212 194
    public void updateCameraInfo(AMapNaviCameraInfo[] aMapNaviCameraInfos) {
213
214 195
    }
215 196
216 197
    @Override
217 198
    public void updateIntervalCameraInfo(AMapNaviCameraInfo aMapNaviCameraInfo, AMapNaviCameraInfo aMapNaviCameraInfo1, int i) {
218
219 199
    }
220 200
221 201
    @Override
222 202
    public void onServiceAreaUpdate(AMapServiceAreaInfo[] aMapServiceAreaInfos) {
223
224 203
    }
225 204
226 205
    @Override
227 206
    public void onNaviInfoUpdate(NaviInfo naviInfo) {
228
229
207
        try {
208
            List<NaviLatLng> naviLatLngList = routeOverLay.getArrowPoints(naviInfo.getCurStep());
209
            routeOverLay.drawArrow(naviLatLngList);
210
        } catch (Exception e) {
211
            e.printStackTrace();
212
        }
230 213
    }
231 214
232 215
    @Override
233 216
    public void OnUpdateTrafficFacility(TrafficFacilityInfo trafficFacilityInfo) {
234
235 217
    }
236 218
237 219
    @Override
238 220
    public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo aMapNaviTrafficFacilityInfo) {
239
240 221
    }
241 222
242 223
    @Override
243 224
    public void showCross(AMapNaviCross aMapNaviCross) {
244
245 225
    }
246 226
247 227
    @Override
248 228
    public void hideCross() {
249
250 229
    }
251 230
252 231
    @Override
253 232
    public void showModeCross(AMapModelCross aMapModelCross) {
254
255 233
    }
256 234
257 235
    @Override
258 236
    public void hideModeCross() {
259
260 237
    }
261 238
262 239
    @Override
263 240
    public void showLaneInfo(AMapLaneInfo[] aMapLaneInfos, byte[] bytes, byte[] bytes1) {
264
265 241
    }
266 242
267 243
    @Override
268 244
    public void showLaneInfo(AMapLaneInfo aMapLaneInfo) {
269
270 245
    }
271 246
272 247
    @Override
273 248
    public void hideLaneInfo() {
274
275 249
    }
276 250
277 251
    @Override
278 252
    public void onCalculateRouteSuccess(int[] ints) {
279
280 253
    }
281 254
282
283 255
    @Override
284 256
    public void notifyParallelRoad(int i) {
285
286 257
    }
287 258
288 259
    @Override
289 260
    public void OnUpdateTrafficFacility(AMapNaviTrafficFacilityInfo[] aMapNaviTrafficFacilityInfos) {
290
291 261
    }
292 262
293 263
    @Override
294 264
    public void updateAimlessModeStatistics(AimLessModeStat aimLessModeStat) {
295
296 265
    }
297 266
298 267
299 268
    @Override
300 269
    public void updateAimlessModeCongestionInfo(AimLessModeCongestionInfo aimLessModeCongestionInfo) {
301
302 270
    }
303 271
304 272
    @Override
305 273
    public void onPlayRing(int i) {
306
307 274
    }
308 275
309 276
    @Override
310 277
    public void onCalculateRouteSuccess(AMapCalcRouteResult aMapCalcRouteResult) {
311
278
        int[] routeIds = aMapCalcRouteResult.getRouteid();
279
        int routeId = routeIds[0];
280
        AMapNaviPath aMapNaviPath = mAMapNavi.getNaviPaths().get(routeId);
281
        routeOverLay = new RouteOverLay(mAMapNaviView.getMap(), aMapNaviPath, SimpleNaviActivity.this);
282
        routeOverLay.setStartPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.icon_newstarr));
283
        routeOverLay.setEndPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.icon_newstopr));
284
        routeOverLay.setWayPointBitmap(BitmapFactory.decodeResource(this.getResources(), R.drawable.icon_sgreen));
285
        routeOverLay.addToMap();
312 286
    }
313 287
314 288
    @Override
315 289
    public void onCalculateRouteFailure(AMapCalcRouteResult aMapCalcRouteResult) {
316
317 290
    }
318 291
319 292
    @Override
320 293
    public void onNaviRouteNotify(AMapNaviRouteNotifyData aMapNaviRouteNotifyData) {
321
322 294
    }
323 295
324 296
    @Override
325 297
    public void onNaviSetting() {
326
327 298
    }
328 299
329 300
    @Override
@ -338,41 +309,33 @@ public class SimpleNaviActivity extends Activity implements AMapNaviListener, AM
338 309
339 310
    @Override
340 311
    public void onNaviMapMode(int i) {
341
342 312
    }
343 313
344 314
    @Override
345 315
    public void onNaviTurnClick() {
346
347 316
    }
348 317
349 318
    @Override
350 319
    public void onNextRoadClick() {
351
352 320
    }
353 321
354 322
    @Override
355 323
    public void onScanViewButtonClick() {
356
357 324
    }
358 325
359 326
    @Override
360 327
    public void onLockMap(boolean b) {
361
362 328
    }
363 329
364 330
    @Override
365 331
    public void onNaviViewLoaded() {
366
367 332
    }
368 333
369 334
    @Override
370 335
    public void onMapTypeChanged(int i) {
371
372 336
    }
373 337
374 338
    @Override
375 339
    public void onNaviViewShowMode(int i) {
376
377 340
    }
378 341
}