2
我已經計算了車輛的速度並將該速度與某個閾值進行比較,即速度< = 3,現在問題是計算等待時間。 我想計算車輛等待時間,如果汽車停留時間超過兩分鐘超過總時間等待超過兩分鐘後將被添加到等待時間..我使用處理程序和可運行內onLocationchanged() 但我的時間計算是隨機。不同的處理程序和可運行程序正在運行,並且時間比定義的要快。無法放置處理程序和內部可運行OnLocationChanged()
@Override
public void onLocationChanged(Location location) {
diaplayViews();
timeGpsUpdate = location.getTime();
float delta = (timeGpsUpdate - timeOld)/1000;
if (location.getAccuracy() <100) {
distance += locationOld.distanceTo(location);
Log.e("location:", location + "");
speed = (long) (distance/delta);
if(speed<=3)
{
if(runable==null)
{
runnable = new Runnable() {
public void run() {
waitingTime++;
updateHandler.postDelayed(this, 10000); // determines the execution interval waiting time addition on every 10 seconds after 2 minutes initially
}
};}
updateHandler.postDelayed(runnable, 60*2*1000); // acts like the initial delay
}
else {
handler.removeCallbacks(runable);
runable=null;
}
locationOld = location;
timeOld = timeGpsUpdate;
diaplayViews();
}
}