有没有办法在特定的intervan上从locationManager请求位置更新并忽略minDistance?我试过了
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 3600 * 1000, 1, this)
但是在日志中有时会显示位置会在几分钟内更新,有时会在半小时内更新......是否可以按固定间隔更新位置并忽略距离?
答案 0 :(得分:1)
您可以使用此架构。创建新的Runnable,每当你想要它时都会调用它
private final Handler _handler = new Handler();
private static int DATA_INTERVAL = 60 * 1000;
private final Runnable getData = new Runnable()
{
@Override
public void run()
{
getDataFrame();
}
};
private void getDataFrame()
{
requestGPS();
Timer time = new Timer();
time.schedule(new TimerTask() {
@Override
public void run() {
_locationManager.removeUpdates(_connector);
this.cancel();
}
}, 5000, 5000);
_handler.postDelayed(getData, DATA_INTERVAL);
}
private void requestGPS()
{
_locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
0,
0,
_connector);
}