Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

update interval in requestLocationUpdates

How can I update time and distance intervals, or call requestLocationUpdates again with different intervals?

My code:

LocationManager locationManager = (LocationManager) activityObject.getSystemService(Context.LOCATION_SERVICE);

    cll = new CheckinLocationListener();

    LocationProvider gps = locationManager.getProvider(LocationManager.GPS_PROVIDER);

    // GPS

    locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, timeDelay, distanceDelay, cll);

    Location location = locationManager.getLastKnownLocation(LocationManager.GPS_PROVIDER);

onLocationChanged:

if(location.getSpeed()>=0 && location.getSpeed()<= 3)
            {
                LocationsModel.this.distanceDelay = 25;
                LocationsModel.this.timeDelay = 10000;
            }
            else if(location.getSpeed()>=3 && location.getSpeed()<= 17)
            {
                LocationsModel.this.distanceDelay = 150;
                LocationsModel.this.timeDelay = 60000;
            }
            else if(location.getSpeed()>=17)
            {
                LocationsModel.this.distanceDelay = 300;
                LocationsModel.this.timeDelay = 240000;
            }

I would like to use the new intervals at the next measure.

like image 392
McDermott Avatar asked Jun 14 '11 08:06

McDermott


1 Answers

You'll need to first call locationManager.removeUpdates( cll ); and then re-register for updates using your new interval.

like image 132
Mark Allison Avatar answered Oct 20 '22 22:10

Mark Allison