Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No location.sample nor extras propertie in location callback #1685

Closed
Stophface opened this issue May 18, 2023 · 3 comments
Closed

No location.sample nor extras propertie in location callback #1685

Stophface opened this issue May 18, 2023 · 3 comments

Comments

@Stophface
Copy link

Your Environment

  • Plugin version: ^4.12.0
  • Platform: iOS or Android iOS
  • OS version: 16.4
  • React Native version (react-native -v): 0.71.7
  • Plugin config
{
      desiredAccuracy: BackgroundGeolocation.DESIRED_ACCURACY_MEDIUM,
      stationaryRadius: 25,
      disableElasticity: true,
      distanceFilter: 50,
      disableLocationAuthorizationAlert: true,
      maxRecordsToPersist: 1,
      stopOnTerminate: true,
      stopTimeout: STOP_TIMEOUT,
      disableMotionActivityUpdates: true,
      debug: false, 
      logLevel: BackgroundGeolocation.LOG_LEVEL_OFF,
      showsBackgroundLocationIndicator: true,
      allowIdenticalLocations: false,
      foregroundService: true,
      locationAuthorizationRequest: 'WhenInUse',
      ...
    }

Expected Behavior & Actual Behavior

I am trying to find out, which points that arrive here

BackgroundGeolocation.onLocation(async location => { 
        ... 
})

are samples. Before calling onLocation() I am calling getCurrentPosition(). If there is a current position (and some other things are fullfilled), I start the location subscription. So I assume there are samples in the onLocation() callback? I have tried

if (location.sample == true) {
    console.log('- location is a sample');
}

But it never logs anything. I checked the location object, and there is no sample prop in there.

{"activity": {"confidence": 100, "type": "unknown"}, "battery": {"is_charging": false, "level": -1}, "coords": {"accuracy": 5, "altitude": 0, "altitude_accuracy": -1, "ellipsoidal_altitude": 0, "floor": 0, "heading": 20.04, "heading_accuracy": 0, "latitude": 37.76147723, "longitude": -122.40613148, "speed": 27.02, "speed_accuracy": 0}, "extras": {"initialPosition": true}, "is_moving": false, "mock": true, "odometer": 17543.9, "timestamp": "2023-05-18T10:04:22.912Z", "uuid": "EC879F80-8704-4131-9C46-40F5645A6384"}

I have tried to modify the getCurrentPosition() call

 await BackgroundGeolocation.getCurrentPosition({
              timeout: 5,
              maximumAge: 1,
              desiredAccuracy: 100,
              samples: 1,
              extras: {
                initialPosition: true,
              },
            });

but extras.initialPosition is not in the location object either. How would I find out, which positions in onLocation() are samples from getCurrentPosition()? Or does the module behave in a way that once the sampling is done with getCurrentPosition() and then, afterwards the subscription to onLocation() is set up, the samples from getCurrentLocation() are not passed to onLocation()?

@christocracy
Copy link
Member

samples: 1,

You asked the plugin to provide only 1 sample, so necessarily this single location must be the final location provided.

Set it higher and you will see samples (samples: 5).

@christocracy
Copy link
Member

desiredAccuracy: 100,

And set this lower (eg: desiredAccuracy: 0).

desiredAccuracy when used with .getCurrentPosition means "If you receive a location with an accuracy <= desiredAccuracy, call that "good enough" and stop sampling"

With {samples: 5, desiredAccuracy: 100}, if the first received location has accuracy 40, the plugin will immediately stop sampling and return that first location as the final location. There will be no reported "samples".

@Stophface
Copy link
Author

I understand, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants