michalchudziak / react-native-geolocation

Geolocation APIs for React Native
MIT License
1.27k stars 219 forks source link

Issue setting `expirationDuration` with `maximumAge` #290

Closed jkaufman closed 6 months ago

jkaufman commented 7 months ago

checkLocationSettings in PlayServicesLocationManager calls setRequestExpirationDuration when evaluating the availability of location data. This method is deprecated and replaced by setDurationMillis, which documents that it ceases all updates if the interval is exceeded. If a location is obtained, the request is passed to mFusedLocationClient.requestLocationUpdates(), preserving the expiration duration.

First, setting a value between zero and max yields a location manager that stops updating after maximumAge ms.

Second, I'm concerned that a maximumAge setting of 0, and thus an expirationDuration of 0, could result in erroneous failures if a location is not obtained immediately, even if location permissions are granted, but I haven't seen this in practice.

I would encourage calling setMaxUpdateAgeMillis() with maximumAge, as this correctly constrains only the maximum age of a cached initial update. I've updated this locally and it appears to work as expected. Note that it requires adopting the LocationRequest.Builder API.