LocationClient receive location updates by distance

I use LocationClientto retrieve the user's current location, and I am trying to create LocationRequestwith distance as well as update interval.

My code is currently requesting location updates by update interval:

        mLocationRequest = LocationRequest.create();
        mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
        mLocationRequest.setInterval(updateInterval);
        mLocationRequest.setFastestInterval(FASTEST_INTERVAL);
        if (mLocationClient.isConnected()) {
            mLocationClient.requestLocationUpdates(mLocationRequest, this);
        }

There LocationManageris a method for requesting location updates for distance.

public void requestLocationUpdates (String provider, long minTime, float minDistance, LocationListener listener)

+4
source share
1 answer

You can use setSmallestDisplacement to set the minimum distance between updates in meters. Just add this to your code.

mLocationRequest.setSmallestDisplacement (SMALLEST_DISPLACEMENT);

+6
source

Source: https://habr.com/ru/post/1547014/


All Articles