当前位置: 代码迷 >> Android >> 安卓实现在百度map上播放历史轨迹
  详细解决方案

安卓实现在百度map上播放历史轨迹

热度:104   发布时间:2016-04-28 03:32:28.0
安卓实现在百度地图上播放历史轨迹

把一个人一个月轨迹历史描绘出来,并实现按时间顺序回放。小弟菜鸟一枚,代码质量不高,高手勿喷,谢谢。

关于描点和描线,百度地图都有自己的API,大家都应该会了;至于播放动画,肯定不止一种方法,如果大家有好的方法,分享出来,小弟感激不尽。

我的方法:在一个线程里,开始播放后,遍历存放item的list,找到当前的item,移除他的marker,然后给他换一个marker,再添加到list里面,然后睡眠;接着就判断,如果不是当前item,该什么样子就什么样子,如此迭代就可以了。



代码如下:

?
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
/** 轨迹回放逻辑处理 **/
    privateRunnable rz = newRunnable()
    {
        @Override
        publicsynchronizedvoid run()
        {
            while(isStartRun)
            {
                for(inti = 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));
                    }
                    elseif(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 = newBitmapDrawable(bmp);
                        item.setMarker(drawable);

                    }
                    if(!isBcak)
                    {
                        break;
                    }
                    mOverlayGraphic.addItem(item);
                    mMapView.refresh();
                    index++;
                    if(!isFinish)
                    {
                        index = 0;
                        sendMsg(MapApplication.LOCATEOVER_PLAY_FINISH);
                        break;
                    }
                }
            }
        }
    };

 

?
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
privateHandler handler = newHandler()
    {
        publicvoidhandleMessage(Message msg)
        {
            switch(msg.what)
            {
                caseMapApplication.LOCATEOVER_CHANGE_MAPVIEW:
                    changeMapView();
                    break;
                caseMapApplication.LOCATE_MAPVIEW_REFRESH:
                    mMapView.refresh();
                    mMapView.getController().zoomToSpan(mOverlayGraphic.getLatSpanE6(), mOverlayGraphic.getLonSpanE6());
                    mMapView.getController().setCenter(mOverlayGraphic.getCenter());
                    PocProgressDialog.cancel();
                    break;
                caseMapApplication.LOCATEOVER_PLAY_FINISH:
                    Toast.makeText(MainActivity.mainActivity,"播放完毕", Toast.LENGTH_SHORT).show();
                    flag = 99999;
                    adapter.notifyDataSetChanged();
                    play.setText("开始回放");
                    break;
                caseMapApplication.LOCATEOVER_NOTICE_ADAPTER:
                    adapter.notifyDataSetChanged();
                    // mListView.setSelection(flag);备用
                    break;
            }
        }
    };

主要的逻辑就在这里了,下面看看效果:



播放前:

 

播放时:


  相关解决方案