android 基於高德地圖的軌跡回放

android 基於高德地圖的軌跡回放

前段時間公司項目有一個需求,就是需要看到設備上傳之後的軌跡路線,並且可以實現回放的整個過程,功能包括路線回放、地圖位置插點、回放之後的軌跡標記顏色、回放加速等功能。下面是開發的整個過程。

首先,軌跡回放是基於地圖做的,我這裏用的是高德地圖,軌跡回放是基於高德地圖3D地圖開發的,2D地圖好像暫時不支持。必要的就是申請高德地圖的key,然後配置到自己的項目裏,這一步就不說了,高德地圖上這些步驟很詳細,也很簡單,直接跳過到開發軌跡回放這一步。

首先上一個效果圖:



開始回放

軌跡地圖頁面

接下來是先接入地圖,初始化整個地圖,這一步也直接跳過吧,我最後會把整個代碼貼出來,如果有需要可以自己看看,直接說軌跡回放在地圖上劃線的代碼:

首先,新建一個存放經緯度的數組:

List<LatLng> points = new ArrayList<LatLng>();

然後把你獲取到的經緯度add到數組裏面

//添加經緯度至數組,添加下標,防止新數據佔用老數據位置

points.add(i, new LatLng(latitude, longitude));

接下來就是用獲取到的經緯度在地圖上添加海量的marker點:

//添加海量marker點

MarkerOptions markerOption= new MarkerOptions();

// markerOption.position(new LatLng(aLocation.getLatitude(), aLocation.getLongitude()));

markerOption.position(new LatLng(latitude, longitude));

markerOption.visible(true);//標記可見

markerOption.icon(

        BitmapDescriptorFactory.fromBitmap(BitmapFactory

                .decodeResource(getResources(),

                        R.drawable.marker_blue)));

markerOption.anchor(0.5f, 0.5f);

Marker marker= aMap.addMarker(markerOption);

// marker.setIcon();

marker.setObject(map);// 這裏可以存儲用戶數據

listMarker.add(marker);

然後在地圖上劃線,就是把points的點連接起來:

/*劃線*/

private void showline() {

    addPolylineInPlayGround();

    Log.e("tag", points.toString());

    // 獲取軌跡座標點

    LatLngBounds.Builder b= LatLngBounds.builder();

    for (int i= 0; i< points.size(); i++) {

        b.include(points.get(i));

}

    LatLngBounds bounds= b.build();

    aMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));

}

/*添加線條*/

private void addPolylineInPlayGround() {

    List list= points;

    List colorList= new ArrayList();

    aMap.addPolyline(new PolylineOptions().setCustomTexture(BitmapDescriptorFactory.fromResource(R.drawable.custtexture)) //setCustomTextureList(bitmapDescriptors)

            .addAll(list)

            .useGradient(true)

            .width(18));

}

現在線已經畫好的,然後就可以進行軌跡回放以及暫停,銷燬,加速的這些步驟:

/*開始移動*/

    public void startMove() {

        final PolylineOptions options= new PolylineOptions();

        State = 1;

        playback = 1;

        play.setVisibility(View.GONE);

        Fast_forward.setVisibility(View.VISIBLE);

        stop.setVisibility(View.VISIBLE);

        tingzhi.setVisibility(View.VISIBLE);

        // 設置滑動的圖標

        smoothMarker.setDescriptor(BitmapDescriptorFactory.fromResource(R.mipmap.carr));

            /*//當移動Marker的當前位置不在軌跡起點,先從當前位置移動到軌跡上,再開始平滑移動            // LatLng drivePoint = points.get(0);//設置小車當前位置,可以是任意點,這裏直接設置爲軌跡起點            LatLng drivePoint = new LatLng(39.980521,116.351905);//設置小車當前位置,可以是任意點Pair pair = PointsUtil.calShortestDistancePoint(points, drivePoint);

points.set(pair.first, drivePoint);

List subList = points.subList(pair.first, points.size());

            // 設置滑動的軌跡左邊點smoothMarker.setPoints(subList);*/

        //計算軌跡運行之後的距離,重新開始回放

        smoothMarker.setPoints(points);//設置平滑移動的軌跡list

        // 設置移動的監聽事件  返回 距終點的距離  單位 米

        smoothMarker.setMoveListener(new SmoothMoveMarker.MoveListener() {

            @Override

            public void move(final double distance) {

                runOnUiThread(new Runnable() {

                    @Override

                    public void run() {

                        //添加快進按鈕,回放速度快進一倍

                        if (speed == 1) {

                            if ((int) distance > 1500000) {

                                smoothMarker.setTotalDuration(500);//設置平滑移動的總時間

                            }

                            if ((int) distance < 1500000 && (int) distance > 100000) {

                                smoothMarker.setTotalDuration(400);//設置平滑移動的總時間

                            }

                            if ((int) distance < 100000 && (int) distance > 50000) {

                                smoothMarker.setTotalDuration(250);//設置平滑移動的總時間

                            }

                            if ((int) distance < 50000 && (int) distance > 10000) {

                                smoothMarker.setTotalDuration(150);//設置平滑移動的總時間

                            }

                            if ((int) distance < 10000) {

                                smoothMarker.setTotalDuration(50);//設置平滑移動的總時間

                            }

                        } else {

                            //正常回放速度

                            if ((int) distance > 1500000) {

                                smoothMarker.setTotalDuration(1000);//設置平滑移動的總時間

                            }

                            if ((int) distance < 1500000 && (int) distance > 100000) {

                                smoothMarker.setTotalDuration(800);//設置平滑移動的總時間

                            }

                            if ((int) distance < 100000 && (int) distance > 50000) {

                                smoothMarker.setTotalDuration(500);//設置平滑移動的總時間

                            }

                            if ((int) distance < 50000 && (int) distance > 10000) {

                                smoothMarker.setTotalDuration(300);//設置平滑移動的總時間

                            }

                            if ((int) distance < 10000) {

                                smoothMarker.setTotalDuration(100);//設置平滑移動的總時間

                            }

}

                        if ((int) distance < 1) {

                            play.setVisibility(View.VISIBLE);

                            stop.setVisibility(View.GONE);

                            tingzhi.setVisibility(View.VISIBLE);

                            Fast_forward.setVisibility(View.GONE);

                        }

                        //獲取當前的移動marker點,設置地圖中心座標點

                        LatLng position= smoothMarker.getPosition();

                        aMap.moveCamera(CameraUpdateFactory.changeLatLng(position));

                        redpoints.add(redpoints.size(), position);

                        aMap.addPolyline(options.color(Color.RED) //setCustomTextureList(bitmapDescriptors)

                                .add(position)

                                .useGradient(true)

                                .visible(true)

                                .width(18));

}

                });

}

        });

        //設置地圖縮放比例

        aMap.moveCamera(CameraUpdateFactory.zoomTo(17));

        smoothMarker.startSmoothMove();

        smoothMarker.getMarker().setVisible(true);

}

    /*停止平滑移動*/

    public void stopMove() {

        State = 2;

        playback = 2;

        smoothMarker.stopMove();

        LatLng position1= smoothMarker.getPosition();

        //暫停之後重新開始回放,繼續之前的路徑

//        smoothMarker.startSmoothMove();

        play.setVisibility(View.VISIBLE);

        stop.setVisibility(View.GONE);

        tingzhi.setVisibility(View.VISIBLE);

        Fast_forward.setVisibility(View.GONE);

}

    /*繼續中斷的軌跡回放路線*/

    public void startmove() {

        State = 3;

        play.setVisibility(View.GONE);

        stop.setVisibility(View.VISIBLE);

        Fast_forward.setVisibility(View.VISIBLE);

        tingzhi.setVisibility(View.VISIBLE);

        smoothMarker.startSmoothMove();

}

    /*停止軌跡回放*/

    public void cease() {

        State = 4;

        playback = 3;

        smoothMarker.destroy();

        play.setVisibility(View.VISIBLE);

        stop.setVisibility(View.GONE);

        tingzhi.setVisibility(View.GONE);

        Fast_forward.setVisibility(View.GONE);

        aMap.clear();

        points.clear();

    }

正常的軌跡回放需求就是這些,如果沒有任何問題的話,軌跡回放以及快進的功能已經做好了,在這裏說一下我的經緯度信息是從百度鷹眼上獲取到的,所以不用進行軌跡糾偏,所以這一步驟我也沒有詳細的研究,大概誤差不會太高。要注意的一點就是給經緯度數組add數據的時候一定要添加下標,不然新的數組會添加到老數據之前,這樣就會造成軌跡回放的時候會先從最後的一段路線開始,結束的時候是第一段路線,所以這裏一定要注意。還有一個小小的問題就是有時候進入頁面的時候路線還是有一點小問題,暫時我還沒想到解決的辦法,歡迎指正。下面是我整個頁面的詳細代碼:

public class MapActivity extends Activity implements View.OnClickListener, AMap.OnMarkerClickListener {

    private List points = new ArrayList();

    private List redpoints = new ArrayList();

    private LinearLayout infoWindowLayout, linear3;

    private TextView title;

    private TextView snippet;

    private MapBean mapbean;

    private LayoutInflater factory;

    private MarkerOptions markerOption;

    private MapView mapView;

    private AMap aMap;

    private OkHttpClient okHttpClient;

    private Handler mHandler = new Handler();

    private ImageView play, stop, massage, tingzhi, Fast_forward;

    private SmoothMoveMarker smoothMarker;

    private PopupWindow popupWindow;

    private CustomPopWindow popupWindow1;

    private String username, key, current_timestamp, type, number, strttime, endtime, url, sensor, Alarmtime, id;

    private ImageView back;

    private List list;

    private String Smessage;

    private ProgressDialogEx progressDlgEx;

    private int State, playback;

    private List listMarker = new ArrayList();

    private int speed = 0;

    @Override

    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_map);

        progressDlgEx = new ProgressDialogEx(this, mHandler);

        factory = LayoutInflater.from(MapActivity.this);

        play = (ImageView) this.findViewById(R.id.play);

        stop = (ImageView) this.findViewById(R.id.stop);

        massage = (ImageView) this.findViewById(R.id.massage);

        massage.setOnClickListener(this);

        back = (ImageView) this.findViewById(R.id.back);

        back.setOnClickListener(this);

        play = (ImageView) this.findViewById(R.id.play);

        play.setOnClickListener(this);

        stop = (ImageView) this.findViewById(R.id.stop);

        stop.setOnClickListener(this);

        tingzhi = (ImageView) this.findViewById(R.id.tingzhi);

        tingzhi.setOnClickListener(this);

        Fast_forward = (ImageView) this.findViewById(R.id.Fast_forward);

        Fast_forward.setOnClickListener(this);

        // 獲取用戶名

        username = SharedPreferencesUtils.getString(MapActivity.this, "userName", "");

        key = Data.getInstance().key;

        //時間戳

        current_timestamp = Data.getInstance().current_timestamp;

        Intent intent= getIntent();

        type = intent.getStringExtra("type");//設備類型  1冷藏車  2保溫箱

        number = intent.getStringExtra("number");//設備號  車牌號或保溫箱號

        strttime = intent.getStringExtra("strttime");//開始時間

        endtime = intent.getStringExtra("endtime");//結束時間

        sensor = intent.getStringExtra("sensor");//sensor

        id = intent.getStringExtra("id");

        mapView = (MapView) findViewById(R.id.map);

        mapView.onCreate(savedInstanceState);// 此方法必須重寫

        init();

        DeviceWorkTime();

        ShowMessage();

}

    /*比較時間截取,分割時間不大於24小時*/

    private void CycleTime(String num, int startdate, int enddate) {

        //相差6天以上

        if (enddate- startdate>= 518400) {

            String onetime= String.valueOf(enddate- 86399);

            String twotime= String.valueOf(Integer.parseInt(onetime) - 86399);

            String thretime= String.valueOf(Integer.parseInt(twotime) - 86399);

            String foretime= String.valueOf(Integer.parseInt(threetime) - 86399);

            String fivetime= String.valueOf(Integer.parseInt(foretime) - 86399);

            String sixtime= String.valueOf(Integer.parseInt(fivetime) - 86399);

            //strttime,sixtime  sixtime,fivetime  fivetime,foretime    foretime,threetime  threetime,twotime  twotime,onetime  onetime,endtime

            show(num, String.valueOf(startdate), sixtime);

            show(num, sixtime, fivetime);

            show(num, fivetime, foretime);

            show(num, foretime, threetime);

            show(num, threetime, twotime);

            show(num, twotime, onetime);

            show(num, onetime, String.valueOf(enddate));

}

        //小於1天

        else if (enddate- startdate< 86400) {

            show(num, String.valueOf(startdate), String.valueOf(enddate));

}

}

    /*獲取設備工作時間段*/

    private void DeviceWorkTime() {

        points.clear();

        new Thread() {

            @Override

            public void run() {

                progressDlgEx.simpleModeShowHandleThread();

                OkHttpClient okHttpClient= new OkHttpClient();

                String format= String.format(KeyPath.Path.head + KeyPath.Path.deviceworktime, username, key, current_timestamp, type, strttime, endtime, id);

                Request build1= new Request.Builder().url(format).build();

                okHttpClient.newCall(build1).enqueue(new Callback() {

                    @Overrid

                    public void onFailure(Call call, IOException e) {

}

                    @Override

                    public void onResponse(Call call, Response response) throws IOException {

                        String string= response.body().string();

                        if (string!= null) {

                            try {

                                final JSONObject jsonObject= new JSONObject(string);

                                int status= jsonObject.getInt("status");

                                if (status== 1) {

                                    mHandler.post(new Runnable() {

                                        @Override

                                        public void run() {

                                            try {

                                                JSONObject data= jsonObject.getJSONObject("data");

                                                JSONArray items= data.getJSONArray("device");

                                                final List listt= JsonUtils.parseJsonArray(items);

                                                Data.getInstance().list = listt;

                                                for (int i= 0; i< listt.size(); i++) {

                                                    Map map= (Map) listt.get(i);

                                                    String boxmac= map.get("boxmac").toString();

                                                    int startdate= Integer.parseInt(map.get("startdate").toString());

                                                    int enddate= Integer.parseInt(map.get("enddate").toString());

                                                    CycleTime(boxmac, startdate, enddate);

}

                                            } catch (JSONException e) {

                                                e.printStackTrace();

}

}

                                    });

}

                            } catch (JSONException e) {

                                e.printStackTrace();

                            } finally {

                                progressDlgEx.closeHandleThread();

}

}

}

                });

}

        }.start();

}

    /**

    * 初始化AMap對象

    */

    private void init() {

        if (aMap == null) {

            aMap = mapView.getMap();

}

        aMap.setOnMarkerClickListener(this);// 設置點擊marker事件監聽器

        smoothMarker = new SmoothMoveMarker(aMap);

}

    /**

    * 方法必須重寫

    */

    @Override

    protected void onResume() {

        super.onResume();

        mapView.onResume()

}


    /**


    * 方法必須重寫


    */


    @Override


    protected void onPause() {


        super.onPause();


        mapView.onPause();


}


    /**


    * 方法必須重寫


    */


    @Override


    protected void onSaveInstanceState(Bundle outState) {


        super.onSaveInstanceState(outState);


        mapView.onSaveInstanceState(outState);


}


    /**


    * 方法必須重寫


    */


    @Override


    protected void onDestroy() {


        super.onDestroy();


        mapView.onDestroy();


}


    /*劃線*/


    private void showline() {


        addPolylineInPlayGround();


        Log.e("tag", points.toString());


        // 獲取軌跡座標點


        LatLngBounds.Builder b= LatLngBounds.builder();


        for (int i= 0; i< points.size(); i++) {


            b.include(points.get(i));


}


        LatLngBounds bounds= b.build();


        aMap.animateCamera(CameraUpdateFactory.newLatLngBounds(bounds, 100));


}


    /*開始移動*/


    public void startMove() {


        final PolylineOptions options= new PolylineOptions();


        State = 1;


        playback = 1;


        play.setVisibility(View.GONE);


        Fast_forward.setVisibility(View.VISIBLE);


        stop.setVisibility(View.VISIBLE);


        tingzhi.setVisibility(View.VISIBLE);


        // 設置滑動的圖標


        smoothMarker.setDescriptor(BitmapDescriptorFactory.fromResource(R.mipmap.carr));


            /*//當移動Marker的當前位置不在軌跡起點,先從當前位置移動到軌跡上,再開始平滑移動            // LatLng drivePoint = points.get(0);//設置小車當前位置,可以是任意點,這裏直接設置爲軌跡起點            LatLng drivePoint = new LatLng(39.980521,116.351905);//設置小車當前位置,可以是任意點Pair pair = PointsUtil.calShortestDistancePoint(points, drivePoint);


points.set(pair.first, drivePoint);


List subList = points.subList(pair.first, points.size());


            // 設置滑動的軌跡左邊點smoothMarker.setPoints(subList);*/


        //計算軌跡運行之後的距離,重新開始回放


        smoothMarker.setPoints(points);//設置平滑移動的軌跡list


        // 設置移動的監聽事件  返回 距終點的距離  單位 米


        smoothMarker.setMoveListener(new SmoothMoveMarker.MoveListener() {


            @Override


            public void move(final double distance) {


                runOnUiThread(new Runnable() {


                    @Override


                    public void run() {


                        //添加快進按鈕,回放速度快進一倍


                        if (speed == 1) {


                            if ((int) distance > 1500000) {


                                smoothMarker.setTotalDuration(500);//設置平滑移動的總時間


                            }


                            if ((int) distance < 1500000 && (int) distance > 100000) {


                                smoothMarker.setTotalDuration(400);//設置平滑移動的總時間


                            }


                            if ((int) distance < 100000 && (int) distance > 50000) {


                                smoothMarker.setTotalDuration(250);//設置平滑移動的總時間


                            }


                            if ((int) distance < 50000 && (int) distance > 10000) {


                                smoothMarker.setTotalDuration(150);//設置平滑移動的總時間


                            }


                            if ((int) distance < 10000) {


                                smoothMarker.setTotalDuration(50);//設置平滑移動的總時間


                            }


                        } else {


                            //正常回放速度


                            if ((int) distance > 1500000) {


                                smoothMarker.setTotalDuration(1000);//設置平滑移動的總時間


                            }


                            if ((int) distance < 1500000 && (int) distance > 100000) {


                                smoothMarker.setTotalDuration(800);//設置平滑移動的總時間


                            }


                            if ((int) distance < 100000 && (int) distance > 50000) {


                                smoothMarker.setTotalDuration(500);//設置平滑移動的總時間


                            }


                            if ((int) distance < 50000 && (int) distance > 10000) {


                                smoothMarker.setTotalDuration(300);//設置平滑移動的總時間


                            }


                            if ((int) distance < 10000) {


                                smoothMarker.setTotalDuration(100);//設置平滑移動的總時間


                            }


}


                        if ((int) distance < 1) {


                            play.setVisibility(View.VISIBLE);


                            stop.setVisibility(View.GONE);


                            tingzhi.setVisibility(View.VISIBLE);


                            Fast_forward.setVisibility(View.GONE);


//                                aMap.clear();


//                                points.clear();


//                                options.addAll(redpoints);


//                                showline();


//                                DeviceWorkTime();


                        }


                        //獲取當前的移動marker點,設置地圖中心座標點


                        LatLng position= smoothMarker.getPosition();


                        aMap.moveCamera(CameraUpdateFactory.changeLatLng(position));


                        redpoints.add(redpoints.size(), position);


//                            options.addAll(redpoints);


//                            options.add(position);


//                            options.width(18);


//                            options.useGradient(true);


//                            options.color(Color.RED);


//                            aMap.addPolyline(options);


                        aMap.addPolyline(options.color(Color.RED) //setCustomTextureList(bitmapDescriptors)


                                .add(position)


                                .useGradient(true)


                                .visible(true)


                                .width(18));


}


                });


}


        });


        //設置地圖縮放比例


        aMap.moveCamera(CameraUpdateFactory.zoomTo(17));


        smoothMarker.startSmoothMove();


        smoothMarker.getMarker().setVisible(true);


}


    /*停止平滑移動*/


    public void stopMove() {


        State = 2;


        playback = 2;


        smoothMarker.stopMove();


        LatLng position1= smoothMarker.getPosition();


        //暫停之後重新開始回放,繼續之前的路徑


//        smoothMarker.startSmoothMove();


        play.setVisibility(View.VISIBLE);


        stop.setVisibility(View.GONE);


        tingzhi.setVisibility(View.VISIBLE);


        Fast_forward.setVisibility(View.GONE);


}


    /*繼續中斷的軌跡回放路線*/


    public void startmove() {


        State = 3;


        play.setVisibility(View.GONE);


        stop.setVisibility(View.VISIBLE);


        Fast_forward.setVisibility(View.VISIBLE);


        tingzhi.setVisibility(View.VISIBLE);


        smoothMarker.startSmoothMove();


}


    /*停止軌跡回放*/


    public void cease() {


        State = 4;


        playback = 3;


        smoothMarker.destroy();


        play.setVisibility(View.VISIBLE);


        stop.setVisibility(View.GONE);


        tingzhi.setVisibility(View.GONE);


        Fast_forward.setVisibility(View.GONE);


        aMap.clear();


        points.clear();


        DeviceWorkTime();


//        List colorList = new ArrayList();


//        aMap.addPolyline(options.setCustomTexture(BitmapDescriptorFactory.fromResource(R.drawable.custtexture)) //setCustomTextureList(bitmapDescriptors)


//                .addAll(points)


//                .useGradient(true)


//                .width(18));


    }


    /*添加線條*/


    private void addPolylineInPlayGround() {


        List list= points;


        List colorList= new ArrayList();


        aMap.addPolyline(new PolylineOptions().setCustomTexture(BitmapDescriptorFactory.fromResource(R.drawable.custtexture)) //setCustomTextureList(bitmapDescriptors)


                .addAll(list)


                .useGradient(true)


                .width(18));


}


    /*百度鷹眼接口返回經緯度數據*/


    public void show(final String num, final String strttime, final String endtime) {


        new Thread() {


            @Override


            public void run() {


                progressDlgEx.simpleModeShowHandleThread();


                OkHttpClient okHttpClient= new OkHttpClient();


//這裏是百度鷹眼的接口,爲了不造成麻煩,我就不發出去了


                Request build1= new Request.Builder().url(format).build();


                okHttpClient.newCall(build1).enqueue(new Callback() {


                    @Override


                    public void onFailure(Call call, IOException e) {


}


                    @Override


                    public void onResponse(Call call, Response response) throws IOException {


                        String string= response.body().string();


                        if (string!= null) {


                            try {


                                final JSONObject jsonObject= new JSONObject(string);


                                int status= jsonObject.getInt("status");


                                if (status== 0) {


                                    mHandler.post(new Runnable() {


                                        @Override


                                        public void run() {


                                            try {


                                                JSONArray pointss= jsonObject.getJSONArray("points");


                                                final List listt= JsonUtils.parseJsonArray(pointss);


                                                for (int i= 0; i< listt.size(); i++) {


                                                    Map map= (Map) listt.get(i);


                                                    final double latitude= Double.parseDouble(map.get("latitude").toString());


                                                    final double longitude= Double.parseDouble(map.get("longitude").toString());


                                                    final String address= map.get("address").toString();


                                                    final int loc_time= Integer.parseInt(map.get("loc_time").toString());


//


                                                    //添加經緯度至數組,添加下標,防止新數據佔用老數據位置


                                                    points.add(i, new LatLng(latitude, longitude));


                                                    //添加海量marker點


                                                    MarkerOptions markerOption= new MarkerOptions();


                                                    // markerOption.position(new LatLng(aLocation.getLatitude(), aLocation.getLongitude()));


                                                    markerOption.position(new LatLng(latitude, longitude));


                                                    markerOption.visible(true);//標記可見


                                                    markerOption.icon(


                                                            BitmapDescriptorFactory.fromBitmap(BitmapFactory


                                                                    .decodeResource(getResources(),


                                                                            R.drawable.marker_blue)));


                                                    markerOption.anchor(0.5f, 0.5f);


                                                    Marker marker= aMap.addMarker(markerOption);


                                                    // marker.setIcon();


                                                    marker.setObject(map);// 這裏可以存儲用戶數據


                                                    listMarker.add(marker);


}


                                                showline();


                                            } catch (JSONException e) {


                                                e.printStackTrace();


}


}


                                    });


}


                            } catch (JSONException e) {


                                e.printStackTrace();


                            } finally {


                                progressDlgEx.closeHandleThread();


}


}


}


                });


}


        }.start();


}


    /**


    * 點擊Marker


*/


    public boolean onMarkerClick(Marker arg0) {


        // TODO Auto-generated method stub


        // String streenName = "中山路";


        Map map= (Map) arg0.getObject();


        final double latitude= Double.parseDouble(map.get("latitude").toString());


        final double longitude= Double.parseDouble(map.get("longitude").toString());


        final String address= map.get("address").toString();


        final int loc_time= Integer.parseInt(map.get("loc_time").toString());


//        arg0.setIcon(BitmapDescriptorFactory.fromResource(R.drawable.purple_pin));


        arg0.setTitle("詳細信息");


        ShowSensor(String.valueOf(loc_time), latitude, longitude, address);


        return false;


}


    @Override


    public void onClick(View v) {


        switch (v.getId()) {


            case R.id.Fast_forward:


                DialogUtils.showPopMsgInHandleThread(MapActivity.this, mHandler, "快進一倍回放!");


                Fast_forward.setVisibility(View.GONE);


                speed = 1;


                break;


            case R.id.back:


                finish();


                points.clear();


                break;


            case R.id.play:


                if (points.size() < 1) {


                    Toast.makeText(MapActivity.this, MapActivity.this.getString(R.string.zwjl), Toast.LENGTH_SHORT).show();


                } else {


                    if (playback == 1) {


                        DialogUtils.showPopMsgInHandleThread(MapActivity.this, mHandler, "請先停止軌跡回放路線!");


                        return;


                    } else {


                        DialogUtils.showPopMsgInHandleThread(MapActivity.this, mHandler, "開始回放軌跡路線!");


                        speed = 0;


                        if (State == 2) {


                            startmove();


                        } else {


                            startMove();


}


}


}


                break;


            case R.id.stop:


                DialogUtils.showPopMsgInHandleThread(MapActivity.this, mHandler, "暫停軌跡回放!");


                speed = 0;


                stopMove();


                break;


            case R.id.tingzhi:


                DialogUtils.showPopMsgInHandleThread(MapActivity.this, mHandler, "停止軌跡回放!");


                cease();


                break;


            case R.id.massage:


                if (points.size() < 1) {


                    Toast.makeText(MapActivity.this, MapActivity.this.getString(R.string.zwjl), Toast.LENGTH_SHORT).show();


                } else {


                    if (popupWindow != null && popupWindow.isShowing()) {


                        return;


}


                    LinearLayout layout= (LinearLayout) getLayoutInflater().inflate(R.layout.map_pop, null);


                    popupWindow = new PopupWindow(layout, ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);


                    //點擊空白處時,隱藏掉pop窗口


                    popupWindow.setFocusable(true);


                    popupWindow.setBackgroundDrawable(new BitmapDrawable());


                    //添加彈出、彈入的動畫


                    popupWindow.setAnimationStyle(R.style.Popupwindow);


                    int[] location= new int[2];


                    massage.getLocationOnScreen(location);


                    popupWindow.showAtLocation(massage, Gravity.CENTER | Gravity.BOTTOM, 0, -location[1]);


                    //添加按鍵事件監聽


                    //setButtonListeners(layout);


                    //添加pop窗口關閉事件,主要是實現關閉時改變背景的透明度


                    //popupWindow.setOnDismissListener(new poponDismissListener());


//backgroundAlpha(1f);


                    linear3 = (LinearLayout) layout.findViewById(R.id.linear3);


                    for (int i= 0; i< Data.getInstance().list.size(); i++) {


                        Map map= (Map) Data.getInstance().list.get(i);


                        String boxmac= map.get("boxmac").toString();


                        int startdate= Integer.parseInt(map.get("startdate").toString());


                        int enddate= Integer.parseInt(map.get("enddate").toString());


                        SplitTime(boxmac, startdate, enddate);


                        Log.e("TAG", boxmac+ startdate+ enddate);


}


}


                break;


            default:


                break;


}


}


}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章