Android Fused Location will not provide periodic updates

I want the fixed location to be fixed every certain minutes and to fix the fixed location every certain minutes and if the user has moved more than certain meters. I tested the logic followed by the code flow (tried it with large parameters, while driving), but it doesn't actually return me periodic location corrections. It will return the location fix immediately when the request starts, and then it will return 1 location fix after a few minutes, but then it will not return the location fix for an hour.

LocationRequest locationRequest = LocationRequest.create();
int priority = PRIORITY_BALANCED_POWER_ACCURACY;
locationRequest.setPriority(priority);
locationRequest.setInterval(localInterval); //set to 6 minutes
locationRequest.setFastestInterval(localFastestInterval); //set to 3 minutes
locationRequest.setSmallestDisplacement(smallestDisplacement); //set to 10 meters
locationRequest.setNumUpdates(numUpdates);  //set to Int.MAX_VALUE
locationRequest.setExpirationDuration(expirationDuration); // set to Long.MAX_VALUE
LocationServices.FusedLocationApi.requestLocationUpdates(locationClient, locationRequest, pendingIntent);

      

If I set the offset to 0, I get periodic location updates. Any idea what's going on?

+1


source to share


1 answer


After a lot of exhaustive testing and experimentation, I've found that if you don't call setFastestInterval

, you will receive periodic updates exactly at the interval set with setInterval

.

However, since other applications can result in very fast location fixes, simply check the box to ignore location fixes delivered faster than a certain time threshold.

As per the documentation: If setFastestInterval(long)

set slower than setInterval(long)

then your effective fastest interval is set to Interval (long), but that doesn't happen: eg. setting the following parameters should give you a hard-coded location fix every 1 minute, but it doesn't (at least on Marshmallow):



interval = 1 min
fastestInterval = 20 min
displacement = 0

      

If anyone can refute my findings with code that would be great.

+1


source







All Articles