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

[Android] getCurrentPosition with coarse location permission only #2041

Closed
emorb opened this issue May 31, 2024 · 2 comments
Closed

[Android] getCurrentPosition with coarse location permission only #2041

emorb opened this issue May 31, 2024 · 2 comments

Comments

@emorb
Copy link

emorb commented May 31, 2024

Hi,
I noticed some weird behavior in Android when using getCurrentPosition() method with a timeout and providing coarse location permission only.

Your Environment

  • Plugin version: 4.16.2
  • Platform: Android
  • OS version: 12
  • Device manufacturer / model: Google Pixel 3a
  • React Native version (react-native -v): 0.72.4
  • Plugin config
BackgroundGeolocation.getCurrentPosition({
  timeout: 5,
  samples: 3,
  desiredAccuracy: 50 // even using 100000 the result is the same
})
  .then((position) => {
    console.log(JSON.stringify(position, null, 2))
  })
  .catch((e) => {
    console.error(e)
  })

Expected Behavior

I expect getCurrentPosition() to ask user coarse or fine location permissions the first time it is invoked.
Since providing coarse position permission is enough for the first call, I expect it to be enough even for the further ones, without asking user to provide fine location (maybe such a behavior should be controlled by a flag or something in the request params).

Actual Behavior

When invoking getCurrentPosition() for the first time, if user only grants coarse location permission, location is returned. Invoking getCurrentPosition() again, a native alert appears asking user to provide fine location.
Moreover, if a timeout is provided, the popup is displayed but a location is returned before user actually chooses to provide fine one or not, making the fine permission request irrelevant.

Steps to Reproduce

  1. Invoke getCurrentPosition()
  2. Grant coarse location permission only
  3. Invoke getCurrentLocation() again
  4. Just wait without closing the native dialog

Context

I want to ask user location accuracy only once, if at least coarse location permission is provided

Debug logs

Logs
PASTE_YOUR_LOGS_HERE
@christocracy
Copy link
Member

.getCurrentPosition always uses highest possible accuracy.

the options.desiredAccuracy has a different meaning with .getCurrentPosition — it means the accuracy you’ll be satisfied with when providing options.samples, where if a location having accuracy <= options.desiredAccuracy arrives, the method will stop further sampling and deliver that location.

@christocracy
Copy link
Member

The permission that will be requested is controlled by Config.locationAuthorizationRequest provided to .ready(config).

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