Commit 05f9cba9a6734213732d28f26a727d224d01d604
1 parent
0fe73493
1 修改查询历史轨迹逻辑,减少高并发
Showing
6 changed files
with
235 additions
and
18 deletions
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/frame/view/CollRunRaceDetailFragmentView.java
| ... | ... | @@ -89,9 +89,6 @@ public class CollRunRaceDetailFragmentView implements MvpView, SensorEventListen |
| 89 | 89 | private LatLng endLatLng; |
| 90 | 90 | private final int START_MARK = 0;//起始点 |
| 91 | 91 | private final int END_MARK = 1;//终止点 |
| 92 | - | |
| 93 | - private String startPoint = "首都师范大学南门"; | |
| 94 | - private String endPoint = "首都师范大学篮球场"; | |
| 95 | 92 | private String test = "[{\"latitude\":39.933889208848,\"latitudeE6\":3.9933889208848E7,\"longitude\":116.30900265517,\"longitudeE6\":1.1630900265517001E8},{\"latitude\":39.933868507347,\"latitudeE6\":3.9933868507347E7,\"longitude\":116.30865416508,\"longitudeE6\":1.1630865416508E8},{\"latitude\":39.934756505077,\"latitudeE6\":3.9934756505077E7,\"longitude\":116.30860516469,\"longitudeE6\":1.1630860516468999E8},{\"latitude\":39.934781620502,\"latitudeE6\":3.9934781620502E7,\"longitude\":116.30961013007,\"longitudeE6\":1.1630961013007E8},{\"latitude\":39.934881620374,\"latitudeE6\":3.9934881620374E7,\"longitude\":116.30960513008,\"longitudeE6\":1.1630960513008E8},{\"latitude\":39.934077623132,\"latitudeE6\":3.9934077623132E7,\"longitude\":116.30965812942,\"longitudeE6\":1.1630965812942E8},{\"latitude\":39.933972618463,\"latitudeE6\":3.9933972618463E7,\"longitude\":116.30962113087,\"longitudeE6\":1.1630962113087E8},{\"latitude\":39.933932608856,\"latitudeE6\":3.9933932608856E7,\"longitude\":116.30953913383,\"longitudeE6\":1.1630953913383E8}]"; |
| 96 | 93 | private LinkedList<LatLng> importLatLngs;//关键点 |
| 97 | 94 | private LatLng startLatLng = new LatLng(39.934733, 116.308646);//起始点 | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/frame/view/CollRunningFinishFragmentView.java
| 1 | 1 | package com.cnlive.moudle.collectionTrace.frame.view; |
| 2 | 2 | |
| 3 | 3 | import android.content.Context; |
| 4 | +import android.graphics.Bitmap; | |
| 5 | +import android.graphics.BitmapFactory; | |
| 4 | 6 | import android.support.v7.widget.LinearLayoutManager; |
| 5 | 7 | import android.text.TextUtils; |
| 6 | 8 | import android.view.View; |
| 7 | 9 | |
| 10 | +import com.baidu.location.LocationClient; | |
| 11 | +import com.baidu.location.LocationClientOption; | |
| 12 | +import com.baidu.mapapi.map.BaiduMap; | |
| 13 | +import com.baidu.mapapi.map.BitmapDescriptorFactory; | |
| 14 | +import com.baidu.mapapi.map.MapView; | |
| 15 | +import com.baidu.mapapi.map.MyLocationConfiguration; | |
| 16 | +import com.baidu.mapapi.map.Overlay; | |
| 17 | +import com.baidu.mapapi.map.UiSettings; | |
| 18 | +import com.baidu.mapapi.model.LatLng; | |
| 19 | +import com.baidu.trace.LBSTraceClient; | |
| 20 | +import com.baidu.trace.model.SortType; | |
| 8 | 21 | import com.cnlive.moudle.collectionTrace.model.CollectPoint; |
| 9 | 22 | import com.cnlive.moudle.collectionTrace.ui.adapter.CollFinishDetaiAdapter; |
| 10 | 23 | import com.cnlive.moudle.collectionTrace.ui.fragment.CollRunningFinishFragment; |
| ... | ... | @@ -13,9 +26,12 @@ import com.cnlive.moudle.pedometer.commonInfo.CommonInfo; |
| 13 | 26 | import com.cnlive.moudle.pedometer.model.RunningFinishBean; |
| 14 | 27 | import com.cnlive.moudle.pedometer.sql.entity.CollUserStepEntity; |
| 15 | 28 | import com.cnlive.moudle.pedometer.ui.fragment.RunningFinishFragment; |
| 29 | +import com.cnlive.moudle.pedometer.utils.BitmapUtil; | |
| 16 | 30 | import com.cnlive.moudle.pedometer.utils.GsonUtil; |
| 31 | +import com.cnlive.moudle.pedometer.utils.MyMapUtil; | |
| 17 | 32 | import com.cnlive.moudle.pedometer.utils.TimeUtil; |
| 18 | 33 | import com.cnlive.strike.application.GlideApp; |
| 34 | +import com.example.moudle_pedometer.R; | |
| 19 | 35 | import com.hannesdorfmann.mosby3.mvp.MvpView; |
| 20 | 36 | |
| 21 | 37 | import java.util.ArrayList; |
| ... | ... | @@ -24,6 +40,11 @@ import java.util.List; |
| 24 | 40 | public class CollRunningFinishFragmentView implements MvpView { |
| 25 | 41 | private CollRunningFinishFragment fragment; |
| 26 | 42 | private CollFinishDetaiAdapter adapter; |
| 43 | + public BaiduMap baiduMap; | |
| 44 | + private MapView mMapView; | |
| 45 | + private UiSettings mUiSettings; | |
| 46 | + private LBSTraceClient mClient = null; | |
| 47 | + private List<Overlay> allMapOverlays; | |
| 27 | 48 | |
| 28 | 49 | public CollRunningFinishFragmentView(CollRunningFinishFragment fragment) { |
| 29 | 50 | this.fragment = fragment; |
| ... | ... | @@ -34,6 +55,40 @@ public class CollRunningFinishFragmentView implements MvpView { |
| 34 | 55 | } |
| 35 | 56 | |
| 36 | 57 | public void initView(CollUserStepEntity collUserStepEntity) { |
| 58 | + allMapOverlays = new ArrayList<>(); | |
| 59 | + //查询用户历史轨迹 | |
| 60 | + if (0 != collUserStepEntity.getStartTimeStamp() && 0 != collUserStepEntity.getFinishTimeStamp()) { | |
| 61 | + long startTime = collUserStepEntity.getStartTimeStamp(); | |
| 62 | + long endTime = collUserStepEntity.getFinishTimeStamp(); | |
| 63 | + //开始查询 | |
| 64 | + MyMapUtil.queryHistoryTrace(getContext(), mClient, CommonInfo.getUserId(getContext()), startTime, endTime, new MyMapUtil.CallBack() { | |
| 65 | + @Override | |
| 66 | + public void success(List<LatLng> resultPoints) { | |
| 67 | + if (null != resultPoints && resultPoints.size() > 1) { | |
| 68 | + //绘制轨迹 | |
| 69 | + MyMapUtil.drawHistoryTrack(getContext(), baiduMap, resultPoints, SortType.asc, R.color.green_round, R.drawable.icon_start, R.drawable.icon_end); | |
| 70 | + } | |
| 71 | + } | |
| 72 | + }); | |
| 73 | + if (!TextUtils.isEmpty(collUserStepEntity.getImportPoint())) { | |
| 74 | + List<CollectPoint> collectPoints = GsonUtil.jsonToList(collUserStepEntity.getImportPoint(), CollectPoint.class); | |
| 75 | + //绘制运营打的点 | |
| 76 | + if (null != collectPoints) { | |
| 77 | + //根据打点集合,自适应缩放 | |
| 78 | + MyMapUtil.setCollMapAutoZoom(baiduMap, collectPoints, -1.5f); | |
| 79 | + for (CollectPoint point : collectPoints) { | |
| 80 | + LatLng markLatLng = new LatLng(point.getLatitude(), point.getLongitude()); | |
| 81 | + if (null != markLatLng) { | |
| 82 | + //将点位显示到地图上 | |
| 83 | + Overlay overlay = MyMapUtil.setMapMarker(getContext(), baiduMap, markLatLng, R.drawable.icon_map_import); | |
| 84 | + if (null != overlay) { | |
| 85 | + allMapOverlays.add(overlay); | |
| 86 | + } | |
| 87 | + } | |
| 88 | + } | |
| 89 | + } | |
| 90 | + } | |
| 91 | + } | |
| 37 | 92 | //设置用户昵称 |
| 38 | 93 | String nickName = CommonInfo.getUserNickName(getContext()); |
| 39 | 94 | fragment.binding.includeFinishUserInfo.tvUserNickName.setText(nickName); |
| ... | ... | @@ -94,4 +149,86 @@ public class CollRunningFinishFragmentView implements MvpView { |
| 94 | 149 | } |
| 95 | 150 | }); |
| 96 | 151 | } |
| 152 | + | |
| 153 | + | |
| 154 | + public void initMap() { | |
| 155 | + this.mMapView = fragment.binding.mapView; | |
| 156 | + if (baiduMap == null) { | |
| 157 | + baiduMap = mMapView.getMap(); | |
| 158 | + } | |
| 159 | + if (mUiSettings == null) { | |
| 160 | + mUiSettings = baiduMap.getUiSettings(); | |
| 161 | + } | |
| 162 | + if (mClient == null) { | |
| 163 | + mClient = new LBSTraceClient(getContext()); | |
| 164 | + } | |
| 165 | + //启动所有手势 | |
| 166 | + mUiSettings.setAllGesturesEnabled(true); | |
| 167 | + //通过设置enable为true或false 选择是否显示缩放按钮 | |
| 168 | + mMapView.showZoomControls(false); | |
| 169 | + mUiSettings.setEnlargeCenterWithDoubleClickEnable(true); | |
| 170 | + //隐藏自带的指南针,改用自定义指南针 杨帅 | |
| 171 | + mUiSettings.setCompassEnabled(false); | |
| 172 | + //显示定位图层 | |
| 173 | + baiduMap.setMyLocationEnabled(false); | |
| 174 | + LocationClientOption option = new LocationClientOption(); | |
| 175 | + option.setOpenGps(true); // 打开gps | |
| 176 | + //可选,设置返回经纬度坐标类型,默认GCJ02 | |
| 177 | + //GCJ02:国测局坐标; | |
| 178 | + //BD09ll:百度经纬度坐标; | |
| 179 | + //BD09:百度墨卡托坐标; | |
| 180 | + //海外地区定位,无需设置坐标类型,统一返回WGS84类型坐标 | |
| 181 | + option.setCoorType("gcj02"); // 设置坐标类型 | |
| 182 | + //可选,默认false,设置是否开启Gps定位 | |
| 183 | + option.setOpenGps(true); | |
| 184 | + //设置打开自动回调位置模式,该开关打开后,期间只要定位SDK检测到位置变化就会主动回调给开发者,该模式下开发者无需再关心定位间隔是多少,定位SDK本身发现位置变化就会及时回调给开发者 | |
| 185 | + option.setOpenAutoNotifyMode(); | |
| 186 | + //可选,默认高精度,设置定位模式,高精度,低功耗,仅设备 | |
| 187 | + //LocationMode.Hight_Accuracy:高精度; | |
| 188 | + //LocationMode. Battery_Saving:低功耗; | |
| 189 | + //LocationMode. Device_Sensors:仅使用设备; | |
| 190 | + option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy); | |
| 191 | + //可选,设置是否需要地址信息,默认不需要 | |
| 192 | + option.setIsNeedAddress(false); | |
| 193 | + //可选,设置是否需要地址描述 | |
| 194 | + option.setIsNeedLocationDescribe(false); | |
| 195 | + //可选,设置是否需要设备方向结果 | |
| 196 | + option.setNeedDeviceDirect(false); | |
| 197 | + //设置打开自动回调位置模式,该开关打开后,期间只要定位SDK检测到位置变化就会主动回调给开发者 | |
| 198 | + //minTimeInterval - 最短定位时间间隔,单位毫秒,最小值0,开发者可以在设置希望的位置回调最短时间间隔 | |
| 199 | + //minDistance - 最短定位距离间隔,单位米,最小值0,开发者可以设置希望的位置回调距离间隔 | |
| 200 | + //locSensitivity - 定位变化敏感程度,LOC_SENSITIVITY_HIGHT,LOC_SENSITIVITY_MIDDLE,LOC_SENSITIVITY_LOW | |
| 201 | + option.setOpenAutoNotifyMode(3000, 1, LocationClientOption.LOC_SENSITIVITY_HIGHT); | |
| 202 | + //可选,定位SDK内部是一个service,并放到了独立进程。 | |
| 203 | + //设置是否在stop的时候杀死这个进程,默认(建议)不杀死,即setIgnoreKillProcess(true) | |
| 204 | + option.setIgnoreKillProcess(true); | |
| 205 | + | |
| 206 | + } | |
| 207 | + | |
| 208 | + public void onResume() { | |
| 209 | + if (null != mMapView) { | |
| 210 | + mMapView.onResume(); | |
| 211 | + } | |
| 212 | + } | |
| 213 | + | |
| 214 | + public void onPause() { | |
| 215 | + if (null != mMapView) { | |
| 216 | + mMapView.onPause(); | |
| 217 | + } | |
| 218 | + } | |
| 219 | + | |
| 220 | + public void onDestroy() { | |
| 221 | + if (null != allMapOverlays) { | |
| 222 | + for (Overlay overlay : allMapOverlays) { | |
| 223 | + overlay.remove(); | |
| 224 | + } | |
| 225 | + allMapOverlays = null; | |
| 226 | + baiduMap.clear(); | |
| 227 | + } | |
| 228 | + | |
| 229 | + if (mMapView != null) { | |
| 230 | + mMapView.onDestroy(); | |
| 231 | + mMapView = null; | |
| 232 | + } | |
| 233 | + } | |
| 97 | 234 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/frame/view/CollRunningMapFragmentView.java
| ... | ... | @@ -100,7 +100,9 @@ public class CollRunningMapFragmentView implements MvpView, SensorEventListener |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | public void initView(RunRaceDetailInfo runRaceDetailInfo) { |
| 103 | + //初始化打点提示框 | |
| 103 | 104 | initSelectDialog(); |
| 105 | + //初始化结束打点提示框 | |
| 104 | 106 | initFinishSelectDialog(); |
| 105 | 107 | this.runRaceDetailInfo = runRaceDetailInfo; |
| 106 | 108 | uid = CollCommonInfo.getUserId(getContext()); |
| ... | ... | @@ -763,6 +765,13 @@ public class CollRunningMapFragmentView implements MvpView, SensorEventListener |
| 763 | 765 | } |
| 764 | 766 | |
| 765 | 767 | public void onDestroy() { |
| 768 | + if (null != allMapOverlays) { | |
| 769 | + for (Overlay overlay : allMapOverlays) { | |
| 770 | + overlay.remove(); | |
| 771 | + } | |
| 772 | + allMapOverlays = null; | |
| 773 | + baiduMap.clear(); | |
| 774 | + } | |
| 766 | 775 | if (mMapView != null) { |
| 767 | 776 | mMapView.onDestroy(); |
| 768 | 777 | mMapView = null; | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/collectionTrace/ui/fragment/CollRunningFinishFragment.java
| ... | ... | @@ -48,6 +48,9 @@ public class CollRunningFinishFragment extends QMUIFragment<CollRunningFinishFra |
| 48 | 48 | @Override |
| 49 | 49 | public void onViewCreated(View view, @Nullable Bundle savedInstanceState) { |
| 50 | 50 | super.onViewCreated(view, savedInstanceState); |
| 51 | + if (null != getMvpView()) { | |
| 52 | + getMvpView().initMap(); | |
| 53 | + } | |
| 51 | 54 | CollUserStepEntity collUserStepEntity = CollStepUtil.getCollUserStepData(getContext(), CommonInfo.getUserId(getContext())); |
| 52 | 55 | if (collUserStepEntity != null) { |
| 53 | 56 | if (getMvpView() != null) { |
| ... | ... | @@ -67,4 +70,28 @@ public class CollRunningFinishFragment extends QMUIFragment<CollRunningFinishFra |
| 67 | 70 | return 0; |
| 68 | 71 | |
| 69 | 72 | } |
| 73 | + | |
| 74 | + @Override | |
| 75 | + public void onResume() { | |
| 76 | + super.onResume(); | |
| 77 | + if (null != getMvpView()) { | |
| 78 | + getMvpView().onResume(); | |
| 79 | + } | |
| 80 | + } | |
| 81 | + | |
| 82 | + @Override | |
| 83 | + public void onPause() { | |
| 84 | + super.onPause(); | |
| 85 | + if (null != getMvpView()) { | |
| 86 | + getMvpView().onPause(); | |
| 87 | + } | |
| 88 | + } | |
| 89 | + | |
| 90 | + @Override | |
| 91 | + public void onDestroy() { | |
| 92 | + super.onDestroy(); | |
| 93 | + if (null != getMvpView()) { | |
| 94 | + getMvpView().onPause(); | |
| 95 | + } | |
| 96 | + } | |
| 70 | 97 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/frame/view/RunningFinishFragmentView.java
| ... | ... | @@ -9,6 +9,7 @@ import com.baidu.mapapi.map.BaiduMap; |
| 9 | 9 | import com.baidu.mapapi.map.MapView; |
| 10 | 10 | import com.baidu.mapapi.map.UiSettings; |
| 11 | 11 | import com.baidu.mapapi.model.LatLng; |
| 12 | +import com.baidu.trace.LBSTraceClient; | |
| 12 | 13 | import com.baidu.trace.model.SortType; |
| 13 | 14 | import com.bumptech.glide.Glide; |
| 14 | 15 | import com.cnlive.moudle.pedometer.commonInfo.CommonInfo; |
| ... | ... | @@ -31,7 +32,6 @@ public class RunningFinishFragmentView implements MvpView { |
| 31 | 32 | public BaiduMap baiduMap; |
| 32 | 33 | private MapView mMapView; |
| 33 | 34 | private UiSettings mUiSettings; |
| 34 | - | |
| 35 | 35 | public RunningFinishFragmentView(RunningFinishFragment fragment) { |
| 36 | 36 | this.fragment = fragment; |
| 37 | 37 | } | ... | ... |
moudle_pedometer/src/main/java/com/cnlive/moudle/pedometer/utils/MyMapUtil.java
| ... | ... | @@ -32,6 +32,7 @@ import com.baidu.trace.model.ProcessOption; |
| 32 | 32 | import com.baidu.trace.model.SortType; |
| 33 | 33 | import com.baidu.trace.model.StatusCodes; |
| 34 | 34 | import com.baidu.trace.model.TransportMode; |
| 35 | +import com.cnlive.moudle.collectionTrace.model.CollectPoint; | |
| 35 | 36 | import com.cnlive.moudle.pedometer.model.Constant; |
| 36 | 37 | import com.cnlive.moudle.pedometer.model.RoutePoint; |
| 37 | 38 | import com.cnlive.moudle.pedometer.service.StepService; |
| ... | ... | @@ -160,6 +161,33 @@ public class MyMapUtil { |
| 160 | 161 | } |
| 161 | 162 | |
| 162 | 163 | /** |
| 164 | + * 根据点位信息,自动缩放地图 | |
| 165 | + * | |
| 166 | + * @param baiduMap | |
| 167 | + * @param trackPoints | |
| 168 | + * @param zoomBy | |
| 169 | + */ | |
| 170 | + public static void setCollMapAutoZoom(BaiduMap baiduMap, List<CollectPoint> trackPoints, float zoomBy) { | |
| 171 | + LatLngBounds.Builder builder = new LatLngBounds.Builder(); | |
| 172 | + List<LatLng> latLngs = new ArrayList<>(); | |
| 173 | + for (int i = 0; i < trackPoints.size(); i++) { | |
| 174 | + latLngs.add(new LatLng(trackPoints.get(i).getLatitude(), trackPoints.get(i).getLongitude())); | |
| 175 | + } | |
| 176 | + for (LatLng latLng : latLngs) { | |
| 177 | + builder.include(latLng); | |
| 178 | + } | |
| 179 | + MapStatusUpdate mapStatusUpdate = MapStatusUpdateFactory.newLatLngBounds(builder.build()); | |
| 180 | + baiduMap.setMapStatus(mapStatusUpdate); | |
| 181 | + MapStatusUpdate msu = MapStatusUpdateFactory.zoomBy(zoomBy); | |
| 182 | + baiduMap.setMapStatus(msu); | |
| 183 | + //自动计算地图缩放 | |
| 184 | +// MapStatus.Builder builder = new MapStatus.Builder(); | |
| 185 | +// builder.target(MyMapUtil.getCenterZoomPosition(trackPoints)); | |
| 186 | +// builder.zoom(MyMapUtil.getZoom(trackPoints)); | |
| 187 | +// baiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(builder.build())); | |
| 188 | + } | |
| 189 | + | |
| 190 | + /** | |
| 163 | 191 | * 判断用户是否完成比赛 |
| 164 | 192 | * |
| 165 | 193 | * @param importPoints |
| ... | ... | @@ -266,8 +294,8 @@ public class MyMapUtil { |
| 266 | 294 | @Override |
| 267 | 295 | public void run() { |
| 268 | 296 | // //间隔3秒查一次 |
| 269 | - queryHistoryTrace(context, mClient, entityName, startTime, endTime, callBack); | |
| 270 | - queryNum++; | |
| 297 | + queryHistoryTrace(context, mClient, entityName, startTime, endTime, callBack); | |
| 298 | + queryNum++; | |
| 271 | 299 | } |
| 272 | 300 | }, 1000); |
| 273 | 301 | } |
| ... | ... | @@ -359,18 +387,21 @@ public class MyMapUtil { |
| 359 | 387 | /** |
| 360 | 388 | * 绘制历史轨迹 |
| 361 | 389 | */ |
| 362 | - public static Overlay drawHistoryTrack(Context context, BaiduMap baiduMap, List<LatLng> points, SortType sortType, int lineColor, int startIconRes, int endIconRes) { | |
| 390 | + public static List<Overlay> drawHistoryTrack(Context context, BaiduMap baiduMap, List<LatLng> points, SortType sortType, int lineColor, int startIconRes, int endIconRes) { | |
| 363 | 391 | // 绘制新覆盖物前,清空之前的覆盖物 |
| 364 | 392 | if (points == null || points.size() == 0 || lineColor == 0) { |
| 365 | 393 | return null; |
| 366 | 394 | } |
| 395 | + List<Overlay> overlayList = new ArrayList<>(); | |
| 367 | 396 | //只有一个点 |
| 368 | 397 | if (points.size() == 1) { |
| 369 | 398 | if (startIconRes != 0) { |
| 370 | 399 | Bitmap pointBitmap = BitmapUtil.getBitmapFromDp(context, BitmapFactory.decodeResource(context.getResources(), startIconRes), 24, 30); |
| 371 | 400 | OverlayOptions startOptions = new MarkerOptions().position(points.get(0)).icon(BitmapDescriptorFactory.fromBitmap(pointBitmap)); |
| 372 | -// .zIndex(9).draggable(true); | |
| 373 | - return baiduMap.addOverlay(startOptions); | |
| 401 | + if (null != startOptions) { | |
| 402 | + overlayList.add(baiduMap.addOverlay(startOptions)); | |
| 403 | + } | |
| 404 | + return overlayList; | |
| 374 | 405 | } else { |
| 375 | 406 | return null; |
| 376 | 407 | } |
| ... | ... | @@ -391,8 +422,10 @@ public class MyMapUtil { |
| 391 | 422 | OverlayOptions startOptions = null; |
| 392 | 423 | if (startIconRes != 0) { |
| 393 | 424 | startPointBitmap = BitmapUtil.getBitmapFromDp(context, BitmapFactory.decodeResource(context.getResources(), startIconRes), 24, 30); |
| 394 | - startOptions = new MarkerOptions().perspective(false).animateType(MarkerOptions.MarkerAnimateType.grow) | |
| 395 | - .position(startPoint).icon(BitmapDescriptorFactory.fromBitmap(startPointBitmap)); | |
| 425 | + if (null != startPointBitmap && null != startPoint) { | |
| 426 | + startOptions = new MarkerOptions().perspective(false).animateType(MarkerOptions.MarkerAnimateType.grow) | |
| 427 | + .position(startPoint).icon(BitmapDescriptorFactory.fromBitmap(startPointBitmap)); | |
| 428 | + } | |
| 396 | 429 | } |
| 397 | 430 | // .zIndex(9).draggable(true); |
| 398 | 431 | // 添加终点图标 |
| ... | ... | @@ -400,21 +433,35 @@ public class MyMapUtil { |
| 400 | 433 | OverlayOptions endOptions = null; |
| 401 | 434 | if (endIconRes != 0) { |
| 402 | 435 | endPointBitmap = BitmapUtil.getBitmapFromDp(context, BitmapFactory.decodeResource(context.getResources(), endIconRes), 24, 30); |
| 403 | - endOptions = new MarkerOptions().position(endPoint).perspective(false).animateType(MarkerOptions.MarkerAnimateType.grow) | |
| 404 | - .icon(BitmapDescriptorFactory.fromBitmap(endPointBitmap)); | |
| 436 | + if (null != endPointBitmap && null != endPoint) { | |
| 437 | + endOptions = new MarkerOptions().position(endPoint).perspective(false).animateType(MarkerOptions.MarkerAnimateType.grow) | |
| 438 | + .icon(BitmapDescriptorFactory.fromBitmap(endPointBitmap)); | |
| 439 | + } | |
| 405 | 440 | } |
| 406 | 441 | // .zIndex(9).draggable(true); |
| 407 | 442 | |
| 408 | 443 | // 添加路线(轨迹) |
| 409 | - OverlayOptions polylineOptions = new PolylineOptions().width(10) | |
| 410 | - .color(context.getResources().getColor(lineColor)).points(points); | |
| 444 | + OverlayOptions polylineOptions = null; | |
| 445 | + if (null != points) { | |
| 446 | + polylineOptions = new PolylineOptions().width(10) | |
| 447 | + .color(context.getResources().getColor(lineColor)).points(points); | |
| 448 | + } | |
| 411 | 449 | if (startOptions != null) { |
| 412 | - baiduMap.addOverlay(startOptions); | |
| 450 | + overlayList.add(baiduMap.addOverlay(startOptions)); | |
| 413 | 451 | } |
| 414 | 452 | if (endOptions != null) { |
| 415 | - baiduMap.addOverlay(endOptions); | |
| 453 | + overlayList.add(baiduMap.addOverlay(endOptions)); | |
| 454 | + } | |
| 455 | + if (null != polylineOptions) { | |
| 456 | + overlayList.add(baiduMap.addOverlay(polylineOptions)); | |
| 457 | + } | |
| 458 | + if (null != overlayList) { | |
| 459 | + return overlayList; | |
| 460 | + } else if (overlayList.size() == 0) { | |
| 461 | + return null; | |
| 462 | + } else { | |
| 463 | + return null; | |
| 416 | 464 | } |
| 417 | - return baiduMap.addOverlay(polylineOptions); | |
| 418 | 465 | } |
| 419 | 466 | |
| 420 | 467 | /** | ... | ... |