0
我在运行中可靠地调节gps更新速率时遇到了困难。下面的方法似乎与我阅读的所有内容保持一致,偶尔会更新一次或两次更新率(例如,每四秒钟读取一次GPS读数),但之后它会保持一定的速率并不再改变。Android LocationManager不会如预期的那样调节
private LocationManager _locationMgr;
private LocationListener _locationListener;
private int _secondsPerUpdate=-1;
// Constructor
public AshGps(Activity l_activity, int l_secondsPerUpdate)
{
_locationMgr = (LocationManager) l_activity.getSystemService(Context.LOCATION_SERVICE);
_locationListener = new mylocationlistener();
_locationMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, l_secondsPerUpdate*1000, 0, _locationListener);
_secondsPerUpdate = l_secondsPerUpdate;
}
// Called up to once every three seconds
// to change the update rate
void ChangeUpdateRate(int l_secondsPerUpdate)
{
if(_secondsPerUpdate != l_secondsPerUpdate)
{
_locationMgr.removeUpdates(_locationListener);
_locationMgr.requestLocationUpdates(LocationManager.GPS_PROVIDER, l_secondsPerUpdate*1000, 0, _locationListener);
_secondsPerUpdate = l_secondsPerUpdate;
}
}
// Methods handles the incoming GPS reading 'event'
private class mylocationlistener implements LocationListener
{
@Override
public void onLocationChanged(Location location)
{
...