我使用location.speed()
函數從GPS獲取我的速度,並將值存儲在nCurrentSpeed
中。 我應該將nCurrentSpeed
值存儲在數組中以獲得應用程序停止時的平均速度嗎?我該怎麼做?將變量值存儲在數組中以查找平均速度
@Override
public void onLocationChanged(Location location) {
TextView dis =(TextView)findViewById(R.id.distance);
TextView time1 =(TextView)findViewById(R.id.time);
Typeface myTypeface = Typeface.createFromAsset(getAssets(), "SPEEDOFONT.TTF");
text2 = (TextView) findViewById(R.id.text2);
text2.setTypeface(myTypeface);
float speed,time, distance;
if (location == null) {
text2.setText("-.- km/h");
} else {
float nCurrentSpeed = location.getSpeed();
speed = (float) (nCurrentSpeed * 3.6);
text2.setText(String.format("%.2f km/h", speed));
time =location.getTime();
time1.setText("" +time);
distance = speed*time;
dis.setText(String.format("%.2f m/s", distance));
}
}
你應該?我不知道。你在做什麼?如果最終只想知道平均速度,只需保持平均值始終保持最新......'average =((average *(numberOfPoints - 1))+ currentSpeed)/ numberOfPoints; ' –
您想要整個旅程的平均值,還是隻想在最後x秒/分鐘/小時內的平均值? – Simon
我實際上想要使用停止按鈕結束整個旅程的平均速度。 –