capacitor-plugins icon indicating copy to clipboard operation
capacitor-plugins copied to clipboard

@capacitor/geolocation - never returns error when GPS not able to return location

Open ASHBAW opened this issue 3 years ago • 12 comments

I am not sure how to detect an error - no location service available (i.e. GPS may be enabled but the device is not able to get the location)?

I have tried wrapping

const coordinates = await Geolocation.getCurrentPosition();

in a try/catch block.

I have also tried the following:

Geolocation.getCurrentPosition().then((coordinates) => {
          console.log('Current lat:', coordinates.coords.latitude);
          console.log('Current long:', coordinates.coords.longitude);
      })
      .catch((error: any) => {
          console.log(error);
      });

by default the timeout is 10000 ms but I am not able to detect an error.

I might be missing something from the documentation that describes this?

When GPS is able to get the location everything works great.

Thanks for any insight.

ASHBAW avatar Feb 15 '22 18:02 ASHBAW

Experiencing a similar issue where it never returns anything. We have no idea in which situations, but it let to deploying a version where users cannot interact with our app any longer.

muuvmuuv avatar Mar 15 '22 12:03 muuvmuuv

Same problem. Plugin doesn't work on fresh ionic 6 installation out of the box. Module doesn't produce errors and doesn't give result. Tested on emulator.

1

2

droppy2014 avatar Mar 20 '22 19:03 droppy2014

I found it out. I set it to enableHighAccuracy:true and it found coordinates Geolocation.getCurrentPosition({enableHighAccuracy:true});

droppy2014 avatar Mar 21 '22 10:03 droppy2014

I also have enableHighAccuracy:true and am able to obtain coordinates when GPS is available.

My issue is when GPS is enabled on a device but is not able to obtain location (say you are in a place where you cannot get the location even though the device has GPS enabled). I get no feedback/error indicating it was not able to obtain the location.

As stated in my first post I tried .catch and try/catch.

Do you have a way to catch an error in the event it is not able to obtain the location coordinates?

ASHBAW avatar Mar 29 '22 14:03 ASHBAW

For the time being I switched to another plugin. It catches error conditions. If this gets resolved I will try this plugin again.

ASHBAW avatar Mar 31 '22 13:03 ASHBAW

For the time being I switched to another plugin. It catches error conditions. If this gets resolved I will try this plugin again.

Which plugin? I’m facing same issue and looking to switch.

daviesdoclc avatar Apr 06 '22 03:04 daviesdoclc

Same problem here but when I restart my application and requesting the geolocation again, the whole app crashes. Is this happening for you also?

MateiNenciu avatar Apr 06 '22 06:04 MateiNenciu

I have an ionic 6 angular application using all capacitor plugins except for this one. For geolocation I am using this cordova plugin: https://www.npmjs.com/package/cordova-plugin-geolocation

npm i cordova-plugin-geolocation
npx cap sync

ASHBAW avatar Apr 07 '22 13:04 ASHBAW

Here is some more information on using capacitor and cordova: https://capacitorjs.com/docs/v2/cordova/using-cordova-plugins

ASHBAW avatar Apr 07 '22 15:04 ASHBAW

Any update on this?

I am guessing the PositionOptions timeout (default 10000 milliseconds) is not working properly.

Any idea how we can check that?

marioshtika avatar Apr 27 '22 11:04 marioshtika

I have similar issue on a emulated device without a gps sensor (tablets/ TVs/ wearables).

My workaround is to reject promise manually after timeout, as in this Stack Overflow answer

piotr-cz avatar May 24 '22 12:05 piotr-cz

In @capacitor/geolocation: ^4.0.0 , Geolocation.checkPermissions() throws the wanted error when no location service available. Small timesaving tip, it literally throws an error instead of returning a rejected promise.

FireStormHR avatar Aug 02 '22 14:08 FireStormHR

In version 4.0.0 of the plugin the logic of getCurrentPosition() has changed internally, give it a try. I can't reproduce, so I'm closing the issue. If somebody is still having issues with version 4.0.0 or newer, create a new issue providing a sample app and more information about the devices where the plugin is not resolving/rejecting.

jcesarmobile avatar Sep 21 '22 13:09 jcesarmobile