我正在尝试以固定的时间间隔定期更新位置。现在,我正在以 2 分钟的间隔进行测试,以确保一切正常。然后我会把它推到更长的时间间隔。
以下是相关代码:
public final int LOCATION_TIMER_RATE=120000;
locationManager = (LocationManager) this.getSystemService(Context.LOCATION_SERVICE);
locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
Log.d("BLAH", "Recorded home location as: (" + location.getLatitude() + "," + location.getLongitude() + ")");
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, LOCATION_TIMER_RATE, 0, locationListener);
如果我请求单个更新,如下所示,我总是会在 20 秒左右得到回复。但是,在那之后,我仍然没有得到我的定期更新:
locationManager.requestSingleUpdate(LocationManager.NETWORK_PROVIDER, locationListener, null);
如果您请求单次更新,是否需要重新安排定期更新?