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

Geolocation: watchPosition() - not working properly on oppo and realme device #24021

Closed
sohamD07 opened this issue Aug 1, 2024 · 1 comment
Closed
Labels
data:api Compat data for Web APIs. https://developer.mozilla.org/docs/Web/API info needed This needs more information to review or act on.

Comments

@sohamD07
Copy link

sohamD07 commented Aug 1, 2024

What type of issue is this?

Other

What information was incorrect, unhelpful, or incomplete?

I have integrated polymer app as webview in the flutter app. In the polymer app, we are using watchposition method to fetch location. We have provided all required permission from flutter app while login to app. It was found that, for oppo and realme device users watchposition method not giving updated location coords. Same coords are getting for 2-3 hours even after changing physical location by user. There is no any environmental issue while fetching location.

What browsers does this problem apply to, if applicable?

Chromium (Chrome, Edge 79+, Opera, Samsung Internet)

What did you expect to see?

Watchposition method should give us the updated location.

Did you test this? If so, how?

Yes, tested on realme and oppo devices.

Can you link to any release notes, bugs, pull requests, or MDN pages related to this?

https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/watchPosition

Do you have anything more you want to share?

      const coords = await new Promise((resolve, reject) => {

        const watcher = navigator.geolocation.watchPosition((position) => {
          const lcoords = {};
          const captureData = ['latitude', 'longitude', 'accuracy'];
          captureData.forEach(key => { lcoords[key] = position.coords[key] || undefined });
          localStorage.removeItem('coords')
          localStorage.setItem('coords', JSON.stringify(lcoords))

          if (lcoords.accuracy < 200) {
            watcher && navigator.geolocation.clearWatch(watcher);
            resolve(lcoords)
          }
        }, (error) => {
          if (error.code === 1) {
            this.fire('show-message', {
              type: 'error',
              message: 'Please allow Location permision to proceed'
            });
          }
          watcher && navigator.geolocation.clearWatch(watcher);
          reject(error);
        }, geoOptions);

        const timer = setTimeout(() => {
          watcher && navigator.geolocation.clearWatch(watcher);
          reject();
        }, maxTimeout * 1000);
        GlobalStorage.setVal('geolocationTimer', timer);
        GlobalStorage.setVal('geolocationWatcher', watcher);
      }, (err) => {
        err(err)
      })

MDN URL

No response

MDN metadata

No response

@queengooborg
Copy link
Contributor

This sounds like it might be a problem with the framework(s) you're using. Have you tried this code in Chrome on Android on those devices, as well as a basic WebView test environment?

(By the way, please note that this isn't a development help forum, so we will not be able to help if it's a framework issue, nor will we be able to provide a workaround if it is a browser issue.)

@queengooborg queengooborg added data:api Compat data for Web APIs. https://developer.mozilla.org/docs/Web/API info needed This needs more information to review or act on. labels Aug 1, 2024
@queengooborg queengooborg closed this as not planned Won't fix, can't repro, duplicate, stale Sep 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data:api Compat data for Web APIs. https://developer.mozilla.org/docs/Web/API info needed This needs more information to review or act on.
Projects
None yet
Development

No branches or pull requests

2 participants