把一个人一个月的轨迹历史描绘出来,并实现按时间顺序回放。小弟菜鸟一枚,代码质量不高,高手勿喷,谢谢。
关于描点和描线,百度地图都有自己的API,大家都应该会了;至于播放动画,肯定不止一种方法,如果大家有好的方法,分享出来,小弟感激不尽。
我的方法是:在一个线程里,开始播放后,遍历存放item的list,找到当前的item,移除他的marker,然后给他换一个marker,再添加到list里面,然后睡眠;接着就判断,如果不是当前item,该什么样子就什么样子,如此迭代就可以了。
代码如下:
/** 轨迹回放逻辑处理 **/ private Runnable rz = new Runnable() { @Override public synchronized void run() { while (isStartRun) { for (int i = index; i < mGeoList.size(); i++) { OverlayItem item = mGeoList.get(i); flag = index; sendMsg(MapApplication.LOCATEOVER_NOTICE_ADAPTER); mOverlayGraphic.removeItem(item); item.setMarker(res.get(3)); if (!isBcak) { break; } mOverlayGraphic.addItem(item); mMapView.refresh(); SystemUtils.sleep(1000); mOverlayGraphic.removeItem(item); if (index == 0) { item.setMarker(res.get(1)); } else if (index == mGeoList.size() - 1) { item.setMarker(res.get(2)); isStartRun = false; isFinish = false; } else { View view = mInflater.inflate(R.layout.overlay_item, null); TextView userItemTv1 = (TextView) view.findViewById(R.id.item_tv1); userItemTv1.setText(index + 1 + ""); Bitmap bmp = userLocateUtil.createNewBitmap(view); Drawable drawable = new BitmapDrawable(bmp); item.setMarker(drawable); } if (!isBcak) { break; } mOverlayGraphic.addItem(item); mMapView.refresh(); index++; if (!isFinish) { index = 0; sendMsg(MapApplication.LOCATEOVER_PLAY_FINISH); break; } } } } }; private Handler handler = new Handler() { public void handleMessage(Message msg) { switch (msg.what) { case MapApplication.LOCATEOVER_CHANGE_MAPVIEW: changeMapView(); break; case MapApplication.LOCATE_MAPVIEW_REFRESH: mMapView.refresh(); mMapView.getController().zoomToSpan(mOverlayGraphic.getLatSpanE6(), mOverlayGraphic.getLonSpanE6()); mMapView.getController().setCenter(mOverlayGraphic.getCenter()); PocProgressDialog.cancel(); break; case MapApplication.LOCATEOVER_PLAY_FINISH: Toast.makeText(MainActivity.mainActivity, "播放完毕", Toast.LENGTH_SHORT).show(); flag = 99999; adapter.notifyDataSetChanged(); play.setText("开始回放"); break; case MapApplication.LOCATEOVER_NOTICE_ADAPTER: adapter.notifyDataSetChanged(); // mListView.setSelection(flag);备用 break; } } };
主要的逻辑就在这里了,下面看看效果:
播放前:
播放时:
左边对应的listview: