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

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

前段時(shí)間公司項(xiàng)目有一個(gè)需求忆家,就是需要看到設(shè)備上傳之后的軌跡路線耘纱,并且可以實(shí)現(xiàn)回放的整個(gè)過(guò)程觅彰,功能包括路線回放拯腮、地圖位置插點(diǎn)篱蝇、回放之后的軌跡標(biāo)記顏色幔崖、回放加速等功能滋迈。下面是開(kāi)發(fā)的整個(gè)過(guò)程罪郊。

首先版确,軌跡回放是基于地圖做的扣囊,我這里用的是高德地圖,軌跡回放是基于高德地圖3D地圖開(kāi)發(fā)的绒疗,2D地圖好像暫時(shí)不支持侵歇。必要的就是申請(qǐng)高德地圖的key,然后配置到自己的項(xiàng)目里吓蘑,這一步就不說(shuō)了惕虑,高德地圖上這些步驟很詳細(xì),也很簡(jiǎn)單磨镶,直接跳過(guò)到開(kāi)發(fā)軌跡回放這一步溃蔫。

首先上一個(gè)效果圖:


開(kāi)始回放
軌跡地圖頁(yè)面

接下來(lái)是先接入地圖,初始化整個(gè)地圖棋嘲,這一步也直接跳過(guò)吧酒唉,我最后會(huì)把整個(gè)代碼貼出來(lái),如果有需要可以自己看看沸移,直接說(shuō)軌跡回放在地圖上劃線的代碼:

首先痪伦,新建一個(gè)存放經(jīng)緯度的數(shù)組:

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

然后把你獲取到的經(jīng)緯度add到數(shù)組里面

//添加經(jīng)緯度至數(shù)組侄榴,添加下標(biāo),防止新數(shù)據(jù)占用老數(shù)據(jù)位置

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

接下來(lái)就是用獲取到的經(jīng)緯度在地圖上添加海量的marker點(diǎn):

//添加海量marker點(diǎn)

MarkerOptions markerOption= new MarkerOptions();

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

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

markerOption.visible(true);//標(biāo)記可見(jiàn)

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);// 這里可以存儲(chǔ)用戶數(shù)據(jù)

listMarker.add(marker);

然后在地圖上劃線网沾,就是把points的點(diǎn)連接起來(lái):

/*劃線*/

private void showline() {

? ? addPolylineInPlayGround();

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

? ? // 獲取軌跡坐標(biāo)點(diǎn)

? ? 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));

}

現(xiàn)在線已經(jīng)畫(huà)好的癞蚕,然后就可以進(jìn)行軌跡回放以及暫停,銷(xiāo)毀辉哥,加速的這些步驟:

/*開(kāi)始移動(dòng)*/

? ? 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);

? ? ? ? // 設(shè)置滑動(dòng)的圖標(biāo)

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

? ? ? ? ? ? /*//當(dāng)移動(dòng)Marker的當(dāng)前位置不在軌跡起點(diǎn)桦山,先從當(dāng)前位置移動(dòng)到軌跡上,再開(kāi)始平滑移動(dòng)? ? ? ? ? ? // LatLng drivePoint = points.get(0);//設(shè)置小車(chē)當(dāng)前位置醋旦,可以是任意點(diǎn)恒水,這里直接設(shè)置為軌跡起點(diǎn)? ? ? ? ? ? LatLng drivePoint = new LatLng(39.980521,116.351905);//設(shè)置小車(chē)當(dāng)前位置,可以是任意點(diǎn)Pair pair = PointsUtil.calShortestDistancePoint(points, drivePoint);

points.set(pair.first, drivePoint);

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

? ? ? ? ? ? // 設(shè)置滑動(dòng)的軌跡左邊點(diǎn)smoothMarker.setPoints(subList);*/

? ? ? ? //計(jì)算軌跡運(yùn)行之后的距離饲齐,重新開(kāi)始回放

? ? ? ? smoothMarker.setPoints(points);//設(shè)置平滑移動(dòng)的軌跡list

? ? ? ? // 設(shè)置移動(dòng)的監(jiān)聽(tīng)事件? 返回 距終點(diǎn)的距離? 單位 米

? ? ? ? smoothMarker.setMoveListener(new SmoothMoveMarker.MoveListener() {

? ? ? ? ? ? @Override

? ? ? ? ? ? public void move(final double distance) {

? ? ? ? ? ? ? ? runOnUiThread(new Runnable() {

? ? ? ? ? ? ? ? ? ? @Override

? ? ? ? ? ? ? ? ? ? public void run() {

? ? ? ? ? ? ? ? ? ? ? ? //添加快進(jìn)按鈕钉凌,回放速度快進(jìn)一倍

? ? ? ? ? ? ? ? ? ? ? ? if (speed == 1) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance > 1500000) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(500);//設(shè)置平滑移動(dòng)的總時(shí)間

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

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

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(400);//設(shè)置平滑移動(dòng)的總時(shí)間

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

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

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(250);//設(shè)置平滑移動(dòng)的總時(shí)間

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

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

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(150);//設(shè)置平滑移動(dòng)的總時(shí)間

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance < 10000) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(50);//設(shè)置平滑移動(dòng)的總時(shí)間

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? } else {

? ? ? ? ? ? ? ? ? ? ? ? ? ? //正常回放速度

? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance > 1500000) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(1000);//設(shè)置平滑移動(dòng)的總時(shí)間

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

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

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(800);//設(shè)置平滑移動(dòng)的總時(shí)間

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

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

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(500);//設(shè)置平滑移動(dòng)的總時(shí)間

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

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

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(300);//設(shè)置平滑移動(dòng)的總時(shí)間

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance < 10000) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(100);//設(shè)置平滑移動(dòng)的總時(shí)間

? ? ? ? ? ? ? ? ? ? ? ? ? ? }

}

? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance < 1) {

? ? ? ? ? ? ? ? ? ? ? ? ? ? play.setVisibility(View.VISIBLE);

? ? ? ? ? ? ? ? ? ? ? ? ? ? stop.setVisibility(View.GONE);

? ? ? ? ? ? ? ? ? ? ? ? ? ? tingzhi.setVisibility(View.VISIBLE);

? ? ? ? ? ? ? ? ? ? ? ? ? ? Fast_forward.setVisibility(View.GONE);

? ? ? ? ? ? ? ? ? ? ? ? }

? ? ? ? ? ? ? ? ? ? ? ? //獲取當(dāng)前的移動(dòng)marker點(diǎn)捂人,設(shè)置地圖中心坐標(biāo)點(diǎn)

? ? ? ? ? ? ? ? ? ? ? ? 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));

}

? ? ? ? ? ? ? ? });

}

? ? ? ? });

? ? ? ? //設(shè)置地圖縮放比例

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

? ? ? ? smoothMarker.startSmoothMove();

? ? ? ? smoothMarker.getMarker().setVisible(true);

}

? ? /*停止平滑移動(dòng)*/

? ? public void stopMove() {

? ? ? ? State = 2;

? ? ? ? playback = 2;

? ? ? ? smoothMarker.stopMove();

? ? ? ? LatLng position1= smoothMarker.getPosition();

? ? ? ? //暫停之后重新開(kāi)始回放御雕,繼續(xù)之前的路徑

//? ? ? ? smoothMarker.startSmoothMove();

? ? ? ? play.setVisibility(View.VISIBLE);

? ? ? ? stop.setVisibility(View.GONE);

? ? ? ? tingzhi.setVisibility(View.VISIBLE);

? ? ? ? Fast_forward.setVisibility(View.GONE);

}

? ? /*繼續(xù)中斷的軌跡回放路線*/

? ? 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();

? ? }

正常的軌跡回放需求就是這些,如果沒(méi)有任何問(wèn)題的話滥搭,軌跡回放以及快進(jìn)的功能已經(jīng)做好了酸纲,在這里說(shuō)一下我的經(jīng)緯度信息是從百度鷹眼上獲取到的,所以不用進(jìn)行軌跡糾偏瑟匆,所以這一步驟我也沒(méi)有詳細(xì)的研究闽坡,大概誤差不會(huì)太高。要注意的一點(diǎn)就是給經(jīng)緯度數(shù)組add數(shù)據(jù)的時(shí)候一定要添加下標(biāo)脓诡,不然新的數(shù)組會(huì)添加到老數(shù)據(jù)之前无午,這樣就會(huì)造成軌跡回放的時(shí)候會(huì)先從最后的一段路線開(kāi)始,結(jié)束的時(shí)候是第一段路線祝谚,所以這里一定要注意。還有一個(gè)小小的問(wèn)題就是有時(shí)候進(jìn)入頁(yè)面的時(shí)候路線還是有一點(diǎn)小問(wèn)題酣衷,暫時(shí)我還沒(méi)想到解決的辦法交惯,歡迎指正。下面是我整個(gè)頁(yè)面的詳細(xì)代碼:

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;

? ? ? ? //時(shí)間戳

? ? ? ? current_timestamp = Data.getInstance().current_timestamp;

? ? ? ? Intent intent= getIntent();

? ? ? ? type = intent.getStringExtra("type");//設(shè)備類(lèi)型? 1冷藏車(chē)? 2保溫箱

? ? ? ? number = intent.getStringExtra("number");//設(shè)備號(hào)? 車(chē)牌號(hào)或保溫箱號(hào)

? ? ? ? strttime = intent.getStringExtra("strttime");//開(kāi)始時(shí)間

? ? ? ? endtime = intent.getStringExtra("endtime");//結(jié)束時(shí)間

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

? ? ? ? id = intent.getStringExtra("id");

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

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

? ? ? ? init();

? ? ? ? DeviceWorkTime();

? ? ? ? ShowMessage();

}

? ? /*比較時(shí)間截取穿仪,分割時(shí)間不大于24小時(shí)*/

? ? 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));

}

}

? ? /*獲取設(shè)備工作時(shí)間段*/

? ? 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對(duì)象

? ? */

? ? private void init() {

? ? ? ? if (aMap == null) {

? ? ? ? ? ? aMap = mapView.getMap();

}

? ? ? ? aMap.setOnMarkerClickListener(this);// 設(shè)置點(diǎn)擊marker事件監(jiān)聽(tīng)器

? ? ? ? smoothMarker = new SmoothMoveMarker(aMap);

}

? ? /**

? ? * 方法必須重寫(xiě)

? ? */

? ? @Override

? ? protected void onResume() {

? ? ? ? super.onResume();

? ? ? ? mapView.onResume()

}


? ? /**


? ? * 方法必須重寫(xiě)


? ? */


? ? @Override


? ? protected void onPause() {


? ? ? ? super.onPause();


? ? ? ? mapView.onPause();


}


? ? /**


? ? * 方法必須重寫(xiě)


? ? */


? ? @Override


? ? protected void onSaveInstanceState(Bundle outState) {


? ? ? ? super.onSaveInstanceState(outState);


? ? ? ? mapView.onSaveInstanceState(outState);


}


? ? /**


? ? * 方法必須重寫(xiě)


? ? */


? ? @Override


? ? protected void onDestroy() {


? ? ? ? super.onDestroy();


? ? ? ? mapView.onDestroy();


}


? ? /*劃線*/


? ? private void showline() {


? ? ? ? addPolylineInPlayGround();


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


? ? ? ? // 獲取軌跡坐標(biāo)點(diǎn)


? ? ? ? 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));


}


? ? /*開(kāi)始移動(dòng)*/


? ? 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);


? ? ? ? // 設(shè)置滑動(dòng)的圖標(biāo)


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


? ? ? ? ? ? /*//當(dāng)移動(dòng)Marker的當(dāng)前位置不在軌跡起點(diǎn)席爽,先從當(dāng)前位置移動(dòng)到軌跡上,再開(kāi)始平滑移動(dòng)? ? ? ? ? ? // LatLng drivePoint = points.get(0);//設(shè)置小車(chē)當(dāng)前位置啊片,可以是任意點(diǎn)只锻,這里直接設(shè)置為軌跡起點(diǎn)? ? ? ? ? ? LatLng drivePoint = new LatLng(39.980521,116.351905);//設(shè)置小車(chē)當(dāng)前位置,可以是任意點(diǎn)Pair pair = PointsUtil.calShortestDistancePoint(points, drivePoint);


points.set(pair.first, drivePoint);


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


? ? ? ? ? ? // 設(shè)置滑動(dòng)的軌跡左邊點(diǎn)smoothMarker.setPoints(subList);*/


? ? ? ? //計(jì)算軌跡運(yùn)行之后的距離紫谷,重新開(kāi)始回放


? ? ? ? smoothMarker.setPoints(points);//設(shè)置平滑移動(dòng)的軌跡list


? ? ? ? // 設(shè)置移動(dòng)的監(jiān)聽(tīng)事件? 返回 距終點(diǎn)的距離? 單位 米


? ? ? ? smoothMarker.setMoveListener(new SmoothMoveMarker.MoveListener() {


? ? ? ? ? ? @Override


? ? ? ? ? ? public void move(final double distance) {


? ? ? ? ? ? ? ? runOnUiThread(new Runnable() {


? ? ? ? ? ? ? ? ? ? @Override


? ? ? ? ? ? ? ? ? ? public void run() {


? ? ? ? ? ? ? ? ? ? ? ? //添加快進(jìn)按鈕齐饮,回放速度快進(jìn)一倍


? ? ? ? ? ? ? ? ? ? ? ? if (speed == 1) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance > 1500000) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(500);//設(shè)置平滑移動(dòng)的總時(shí)間


? ? ? ? ? ? ? ? ? ? ? ? ? ? }


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


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(400);//設(shè)置平滑移動(dòng)的總時(shí)間


? ? ? ? ? ? ? ? ? ? ? ? ? ? }


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


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(250);//設(shè)置平滑移動(dòng)的總時(shí)間


? ? ? ? ? ? ? ? ? ? ? ? ? ? }


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


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(150);//設(shè)置平滑移動(dòng)的總時(shí)間


? ? ? ? ? ? ? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance < 10000) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(50);//設(shè)置平滑移動(dòng)的總時(shí)間


? ? ? ? ? ? ? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ? ? ? ? ? } else {


? ? ? ? ? ? ? ? ? ? ? ? ? ? //正尘枇龋回放速度


? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance > 1500000) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(1000);//設(shè)置平滑移動(dòng)的總時(shí)間


? ? ? ? ? ? ? ? ? ? ? ? ? ? }


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


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(800);//設(shè)置平滑移動(dòng)的總時(shí)間


? ? ? ? ? ? ? ? ? ? ? ? ? ? }


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


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(500);//設(shè)置平滑移動(dòng)的總時(shí)間


? ? ? ? ? ? ? ? ? ? ? ? ? ? }


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


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(300);//設(shè)置平滑移動(dòng)的總時(shí)間


? ? ? ? ? ? ? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ? ? ? ? ? ? ? if ((int) distance < 10000) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? smoothMarker.setTotalDuration(100);//設(shè)置平滑移動(dòng)的總時(shí)間


? ? ? ? ? ? ? ? ? ? ? ? ? ? }


}


? ? ? ? ? ? ? ? ? ? ? ? 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();


? ? ? ? ? ? ? ? ? ? ? ? }


? ? ? ? ? ? ? ? ? ? ? ? //獲取當(dāng)前的移動(dòng)marker點(diǎn),設(shè)置地圖中心坐標(biāo)點(diǎn)


? ? ? ? ? ? ? ? ? ? ? ? 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));


}


? ? ? ? ? ? ? ? });


}


? ? ? ? });


? ? ? ? //設(shè)置地圖縮放比例


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


? ? ? ? smoothMarker.startSmoothMove();


? ? ? ? smoothMarker.getMarker().setVisible(true);


}


? ? /*停止平滑移動(dòng)*/


? ? public void stopMove() {


? ? ? ? State = 2;


? ? ? ? playback = 2;


? ? ? ? smoothMarker.stopMove();


? ? ? ? LatLng position1= smoothMarker.getPosition();


? ? ? ? //暫停之后重新開(kāi)始回放祖驱,繼續(xù)之前的路徑


//? ? ? ? smoothMarker.startSmoothMove();


? ? ? ? play.setVisibility(View.VISIBLE);


? ? ? ? stop.setVisibility(View.GONE);


? ? ? ? tingzhi.setVisibility(View.VISIBLE);


? ? ? ? Fast_forward.setVisibility(View.GONE);


}


? ? /*繼續(xù)中斷的軌跡回放路線*/


? ? 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));


}


? ? /*百度鷹眼接口返回經(jīng)緯度數(shù)據(jù)*/


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


? ? ? ? new Thread() {


? ? ? ? ? ? @Override


? ? ? ? ? ? public void run() {


? ? ? ? ? ? ? ? progressDlgEx.simpleModeShowHandleThread();


? ? ? ? ? ? ? ? OkHttpClient okHttpClient= new OkHttpClient();


//這里是百度鷹眼的接口握恳,為了不造成麻煩,我就不發(fā)出去了


? ? ? ? ? ? ? ? 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());


//


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //添加經(jīng)緯度至數(shù)組捺僻,添加下標(biāo)乡洼,防止新數(shù)據(jù)占用老數(shù)據(jù)位置


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


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? //添加海量marker點(diǎn)


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? MarkerOptions markerOption= new MarkerOptions();


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


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


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? markerOption.visible(true);//標(biāo)記可見(jiàn)


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? 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);// 這里可以存儲(chǔ)用戶數(shù)據(jù)


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? listMarker.add(marker);


}


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? showline();


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? } catch (JSONException e) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? e.printStackTrace();


}


}


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? });


}


? ? ? ? ? ? ? ? ? ? ? ? ? ? } catch (JSONException e) {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? e.printStackTrace();


? ? ? ? ? ? ? ? ? ? ? ? ? ? } finally {


? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? progressDlgEx.closeHandleThread();


}


}


}


? ? ? ? ? ? ? ? });


}


? ? ? ? }.start();


}


? ? /**


? ? * 點(diǎn)擊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("詳細(xì)信息");


? ? ? ? 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, "快進(jìn)一倍回放!");


? ? ? ? ? ? ? ? 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, "請(qǐng)先停止軌跡回放路線匕坯!");


? ? ? ? ? ? ? ? ? ? ? ? return;


? ? ? ? ? ? ? ? ? ? } else {


? ? ? ? ? ? ? ? ? ? ? ? DialogUtils.showPopMsgInHandleThread(MapActivity.this, mHandler, "開(kāi)始回放軌跡路線束昵!");


? ? ? ? ? ? ? ? ? ? ? ? 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);


? ? ? ? ? ? ? ? ? ? //點(diǎn)擊空白處時(shí)妻怎,隱藏掉pop窗口


? ? ? ? ? ? ? ? ? ? popupWindow.setFocusable(true);


? ? ? ? ? ? ? ? ? ? popupWindow.setBackgroundDrawable(new BitmapDrawable());


? ? ? ? ? ? ? ? ? ? //添加彈出、彈入的動(dòng)畫(huà)


? ? ? ? ? ? ? ? ? ? popupWindow.setAnimationStyle(R.style.Popupwindow);


? ? ? ? ? ? ? ? ? ? int[] location= new int[2];


? ? ? ? ? ? ? ? ? ? massage.getLocationOnScreen(location);


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


? ? ? ? ? ? ? ? ? ? //添加按鍵事件監(jiān)聽(tīng)


? ? ? ? ? ? ? ? ? ? //setButtonListeners(layout);


? ? ? ? ? ? ? ? ? ? //添加pop窗口關(guān)閉事件泞歉,主要是實(shí)現(xiàn)關(guān)閉時(shí)改變背景的透明度


? ? ? ? ? ? ? ? ? ? //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;


}


}


}


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
  • 序言:七十年代末逼侦,一起剝皮案震驚了整個(gè)濱河市,隨后出現(xiàn)的幾起案子腰耙,更是在濱河造成了極大的恐慌榛丢,老刑警劉巖,帶你破解...
    沈念sama閱讀 221,198評(píng)論 6 514
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件挺庞,死亡現(xiàn)場(chǎng)離奇詭異晰赞,居然都是意外死亡,警方通過(guò)查閱死者的電腦和手機(jī)选侨,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 94,334評(píng)論 3 398
  • 文/潘曉璐 我一進(jìn)店門(mén)掖鱼,熙熙樓的掌柜王于貴愁眉苦臉地迎上來(lái),“玉大人援制,你說(shuō)我怎么就攤上這事戏挡。” “怎么了晨仑?”我有些...
    開(kāi)封第一講書(shū)人閱讀 167,643評(píng)論 0 360
  • 文/不壞的土叔 我叫張陵褐墅,是天一觀的道長(zhǎng)。 經(jīng)常有香客問(wèn)我洪己,道長(zhǎng)妥凳,這世上最難降的妖魔是什么? 我笑而不...
    開(kāi)封第一講書(shū)人閱讀 59,495評(píng)論 1 296
  • 正文 為了忘掉前任答捕,我火速辦了婚禮逝钥,結(jié)果婚禮上,老公的妹妹穿的比我還像新娘拱镐。我一直安慰自己艘款,他們只是感情好持际,可當(dāng)我...
    茶點(diǎn)故事閱讀 68,502評(píng)論 6 397
  • 文/花漫 我一把揭開(kāi)白布。 她就那樣靜靜地躺著磷箕,像睡著了一般选酗。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上岳枷,一...
    開(kāi)封第一講書(shū)人閱讀 52,156評(píng)論 1 308
  • 那天芒填,我揣著相機(jī)與錄音,去河邊找鬼空繁。 笑死殿衰,一個(gè)胖子當(dāng)著我的面吹牛,可吹牛的內(nèi)容都是我干的盛泡。 我是一名探鬼主播闷祥,決...
    沈念sama閱讀 40,743評(píng)論 3 421
  • 文/蒼蘭香墨 我猛地睜開(kāi)眼,長(zhǎng)吁一口氣:“原來(lái)是場(chǎng)噩夢(mèng)啊……” “哼傲诵!你這毒婦竟也來(lái)了凯砍?” 一聲冷哼從身側(cè)響起,我...
    開(kāi)封第一講書(shū)人閱讀 39,659評(píng)論 0 276
  • 序言:老撾萬(wàn)榮一對(duì)情侶失蹤拴竹,失蹤者是張志新(化名)和其女友劉穎悟衩,沒(méi)想到半個(gè)月后,有當(dāng)?shù)厝嗽跇?shù)林里發(fā)現(xiàn)了一具尸體栓拜,經(jīng)...
    沈念sama閱讀 46,200評(píng)論 1 319
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡座泳,尸身上長(zhǎng)有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 38,282評(píng)論 3 340
  • 正文 我和宋清朗相戀三年,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了幕与。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片挑势。...
    茶點(diǎn)故事閱讀 40,424評(píng)論 1 352
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡,死狀恐怖啦鸣,靈堂內(nèi)的尸體忽然破棺而出潮饱,到底是詐尸還是另有隱情,我是刑警寧澤赏陵,帶...
    沈念sama閱讀 36,107評(píng)論 5 349
  • 正文 年R本政府宣布饼齿,位于F島的核電站,受9級(jí)特大地震影響蝙搔,放射性物質(zhì)發(fā)生泄漏。R本人自食惡果不足惜考传,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 41,789評(píng)論 3 333
  • 文/蒙蒙 一吃型、第九天 我趴在偏房一處隱蔽的房頂上張望。 院中可真熱鬧僚楞,春花似錦勤晚、人聲如沸枉层。這莊子的主人今日做“春日...
    開(kāi)封第一講書(shū)人閱讀 32,264評(píng)論 0 23
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽(yáng)鸟蜡。三九已至,卻和暖如春挺邀,著一層夾襖步出監(jiān)牢的瞬間揉忘,已是汗流浹背。 一陣腳步聲響...
    開(kāi)封第一講書(shū)人閱讀 33,390評(píng)論 1 271
  • 我被黑心中介騙來(lái)泰國(guó)打工端铛, 沒(méi)想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留泣矛,地道東北人。 一個(gè)月前我還...
    沈念sama閱讀 48,798評(píng)論 3 376
  • 正文 我出身青樓禾蚕,卻偏偏與公主長(zhǎng)得像您朽,于是被迫代替她去往敵國(guó)和親。 傳聞我的和親對(duì)象是個(gè)殘疾皇子换淆,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 45,435評(píng)論 2 359