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