Closed
Description
The current implementation of the geolocation API always reverts back to an accuracy of 100m after receiving the first location update.
- Code snippet
https://facebook.github.io/react-native/docs/geolocation.html
componentDidMount() {
this.startGpsWatch();
}
startGpsWatch() {
let geoOptions :GeoOptions = {
enableHighAccuracy: true,
distanceFilter: 3,
timeout: 20000,
maximumAge: 4000,
accuracy: 1,
};
this.watchID = navigator.geolocation.watchPosition(
this.onLastPositionReceived.bind(this),
this.onLastPositionError.bind(this),
geoOptions
);
onLastPositionReceived(position) {
console.info("accuracy", position.accuracy);
}
- What's the version of React Native you're using?
latest 0.26.1
- Does this occur on iOS, Android or both?
only on iOS
- Are you using Mac, Linux or Windows?
Mac
The issue seems to stem from this code
- (void)locationManager:(CLLocationManager *)manager
didUpdateLocations:(NSArray<CLLocation *> *)locations
{
...
// Reset location accuracy if desiredAccuracy is changed.
// Otherwise update accuracy will force triggering didUpdateLocations, watchPosition would keeping receiving location updates, even there's no location changes.
if (ABS(_locationManager.desiredAccuracy - RCT_DEFAULT_LOCATION_ACCURACY) > 0.000001) {
_locationManager.desiredAccuracy = RCT_DEFAULT_LOCATION_ACCURACY;
}
Where RCT_DEFAULT_LOCATION_ACCURACY
is 100m.
The rationale for this code is somewhat unclear to me. The comment does not seem to fit to the implementation.
Activity