Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to change FusedLocationApi update interval after requestLocationUpdates has been called

I am using LocationServices.FusedLocationApi to get location updates at a given interval, which is set on the LocationRequest object that is passed to requestLocationUpdates:

mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(30000);
LocationServices.FusedLocationApi.requestLocationUpdates(
            mGoogleApiClient, mLocationRequest, this);

I need to change the value of the interval after the listener started to receive location updates. What is the proper way to do that?

like image 566
Pier-Luc Brault Avatar asked Sep 22 '15 15:09

Pier-Luc Brault


1 Answers

    //remove location updates so that it resets
    LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleApiClient, this);

    //change the time of location updates
    mLocationRequest = LocationRequest.create()
            .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
            .setInterval(TIME_INTERVAL)
            .setFastestInterval(TIME_INTERVAL_MIN);

    //restart location updates with the new interval
    LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
like image 142
mikebertiean Avatar answered Oct 13 '22 09:10

mikebertiean