0
Iam開發一個應用程序,通過使用Handler每秒執行一些場信號強度計算,並且在處理程序期間它記錄座標並記錄結果&座標。它工作正常,除非真正的測試和我增加車輛的記錄座標不是每秒鐘的速度,而有時每2-3-4秒不接受我。 下面的代碼:位置更新
final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
publicvoid method_01(LocationManager locationManager){
final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
@Override
public void run() {
Location locationDataRate = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);
double latitude = locationDataRate.getLatitude();
double longitude = locationDataRate.getLongitude();
x=y+1;
Save to file (latitude,longitude,x);
handler.postDelayed(this, 1000);
}
}, 1000);
}
我曾嘗試也改變了時間和分鐘。距離(1000,0)
您需要訂閱位置更改 locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER,2000,1f,yourListener); –