browser-compat-data icon indicating copy to clipboard operation
browser-compat-data copied to clipboard

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

Open sohamD07 opened this issue 1 year ago • 1 comments

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

sohamD07 avatar Aug 01 '24 13:08 sohamD07

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 avatar Aug 01 '24 20:08 queengooborg