Skip to content

Geolocation API automatically reverts to 100m accuracy on iOS #7680

Closed
@rburgst

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

if (ABS(_locationManager.desiredAccuracy - RCT_DEFAULT_LOCATION_ACCURACY) > 0.000001) {

- (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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions