ionic-team / capacitor-plugins

Official plugins for Capacitor ⚡️
531 stars 596 forks source link

@capacitor/geolocation sometimes not working #2165

Open fg1998 opened 3 months ago

fg1998 commented 3 months ago

Bug Report

Plugin(s)

@capacitor/geolocation

Capacitor Version

@capacitor/ios: not installed @capacitor/cli: 6.1.1 @capacitor/core: 6.1.0 @capacitor/android: 6.1.0

VM3:339 result Geolocation.getCurrentPosition (#95975845)
VM3:347 {message: 'location unavailable'}

Platform(s)

ANDROID

Current Behavior

Sometimes Geolocation.getCurrentPosition() simples does not provide any coordinates, just return LOCATION UNAVAILABLE. This issue occurs sometimes after install app, or after live run. But not all times. When this issue occurs, I just open Google Maps and the dot with my current position is GRAY. After 1 or 2 seconds, it became blue and than the error on capacitor does not occur anymore

Code Reproduction

async getCoordenadas() { try { const resp = await Geolocation.getCurrentPosition();

  return {
    error: false,
    latitude: resp.coords.latitude,
    longitude: resp.coords.longitude,
    msg: '',
  };
} catch (err: any) {
  return {
    error: true,
    msg: `GetCoordenadas: ` + err.message,
    latitude: 0,
    longitude: 0,
  };
}

}

Other Technical Details

Galaxy A54, Galaxy S9, Galaxy S10 Lite

Ionitron commented 3 months ago

This issue needs more information before it can be addressed. In particular, the reporter needs to provide a minimal sample app that demonstrates the issue. If no sample app is provided within 15 days, the issue will be closed.

Please see the Contributing Guide for how to create a Sample App.

Thanks! Ionitron 💙

fg1998 commented 3 months ago

Ok, there is it

https://github.com/fg1998/geolocation-bug

The error occurs occasionally. But the screenshots prove the error.

Running on physical device Samsung Galaxy a54 and Samsung Galaxy S10 lite

Gollm commented 2 months ago

I can confirm that users report the same behavior. (Since Capacitor version 6, but it does not necessarily have to be due to the version. The Android hardware or software may also have something to do with it) and I have also seen the error message before.

But as already written: Quite sporadic and cannot be firmly defined.

emnljs commented 2 months ago

Yes I can confirm also I'm using physical devices that shows the "location unavailable" error. I did @fg1998's technique of "restarting" the location by opening Google Maps and it works again.