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

bug: Geolocation.getCurrentPosition() always returns "location unavailable" error message in Android simulator #2854

Closed
1 of 4 tasks
ksouthworth opened this issue Apr 30, 2020 · 6 comments

Comments

@ksouthworth
Copy link

ksouthworth commented Apr 30, 2020

Bug Report

Capacitor Version

npx cap doctor output:
💊 Capacitor Doctor 💊

Latest Dependencies:

@capacitor/cli: 2.0.2

@capacitor/core: 2.0.2

@capacitor/android: 2.0.2

@capacitor/electron: 2.0.2

@capacitor/ios: 2.0.2

Installed Dependencies:

@capacitor/electron not installed

@capacitor/cli 2.0.2

@capacitor/core 2.0.2

@capacitor/ios 2.0.2

@capacitor/android 2.0.2

[success] Android looking great! 👌
Found 4 Capacitor plugins for ios:
cordova-plugin-app-version (0.1.9)
cordova-plugin-ionic (5.4.6)
cordova-plugin-nativegeocoder (3.4.0)
cordova-plugin-whitelist (1.3.4)
[success] iOS looking great! 👌

Affected Platform(s)

  • Android
  • iOS
  • Electron
  • Web

Current Behavior

Calling Geolocation.getCurrentPosition() always returns the error location unavailable from inside the Android simulator (AVD) for Android API versions 29 and 28. iOS simulators are working fine.

Expected Behavior

The current coordinates should be returned when in the Android simulator.

Sample Code or Sample Application Repo

Reproduction Steps

Other Technical Details

npm --version output:
6.14.4

node --version output:
v10.16.0

pod --version output (iOS issues only):

Other Information

Logcat error message:
D/Capacitor: Sending plugin error: {"save":false,"callbackId":"49816472","pluginId":"Geolocation","methodName":"getCurrentPosition","success":false,"error":{"message":"location unavailable"}}

I have the following already added in AndroidManifest.xml

    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-feature android:name="android.hardware.location.gps" />
@jcesarmobile
Copy link
Member

did you enable localization in the emulator? it's disabled by default

@jcesarmobile jcesarmobile added the needs reply needs reply from the user label Apr 30, 2020
@ksouthworth
Copy link
Author

did you enable localization in the emulator? it's disabled by default

@jcesarmobile where or how do I enable localization? If I open the built-in Google Maps app on the emulator it works just fine, so it seems like GPS is working at the emulator level, just not getting a location value from the Capacitor Geolocation plugin.

@jcesarmobile
Copy link
Member

I've been doing some tests and doesn't happen if you use { enableHighAccuracy: true }.
When using { enableHighAccuracy: true }, the location priority is set to PRIORITY_HIGH_ACCURACY, if not, it uses PRIORITY_BALANCED_POWER_ACCURACY and looks like PRIORITY_BALANCED_POWER_ACCURACY doesn't work if the there is no network provider available.

I don't really know how the user can manually configure the location to use the network provider, I can't find the option on settings, but all my devices have them available.
In the simulator I've been able to enable them by using Google Maps for a while, then I get a prompt that says "For better experience, turn on device location, which uses Google's location service". If I click ok then it enables the network provider somehow and location will work fine in my app too.

We could add the code to make the app show that prompt too, but it's very complex and this is not a common scenario, so not sure if it's worth it.

For now I've added some code to check if the network provider is available and if not, use PRIORITY_LOW_POWER, which returns the location just fine (but might be less accurate).

@ZhongYueHui
Copy link

capacitor 的定位失败 不论使用何种方式 在android 都将显示未授权

royscheepens added a commit to pace/cloud-sdk-ionic-example-app that referenced this issue May 4, 2021
@maxiiss
Copy link

maxiiss commented Aug 6, 2021

I've been doing some tests and doesn't happen if you use { enableHighAccuracy: true }.
When using { enableHighAccuracy: true }, the location priority is set to PRIORITY_HIGH_ACCURACY, if not, it uses PRIORITY_BALANCED_POWER_ACCURACY and looks like PRIORITY_BALANCED_POWER_ACCURACY doesn't work if the there is no network provider available.

I don't really know how the user can manually configure the location to use the network provider, I can't find the option on settings, but all my devices have them available.
In the simulator I've been able to enable them by using Google Maps for a while, then I get a prompt that says "For better experience, turn on device location, which uses Google's location service". If I click ok then it enables the network provider somehow and location will work fine in my app too.

We could add the code to make the app show that prompt too, but it's very complex and this is not a common scenario, so not sure if it's worth it.

For now I've added some code to check if the network provider is available and if not, use PRIORITY_LOW_POWER, which returns the location just fine (but might be less accurate).

Hello @jcesarmobile,

I'm facing the same issue... I'm a newbie considering Android development thus i didn't really understand how you specified 'PRIORITY_LOW_POWER'. Is it in the vuejs code or somewhere in the Android project ?

If you have some code example I would be glad to test it.

Thanks you in advance for your response.

@ionitron-bot
Copy link

ionitron-bot bot commented Nov 11, 2022

Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Capacitor, please create a new issue and ensure the template is fully filled out.

@ionitron-bot ionitron-bot bot locked and limited conversation to collaborators Nov 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants