capacitor: bug: Geolocation on Android always returning 'location unavailable'
Bug Report
Capacitor Version
š Capacitor Doctor š
Latest Dependencies:
@capacitor/cli: 3.2.0
@capacitor/core: 3.2.0
@capacitor/android: 3.2.0
@capacitor/ios: 3.2.0
Installed Dependencies:
@capacitor/cli: 3.0.0
@capacitor/core: 3.0.0
@capacitor/android: 3.0.0
@capacitor/ios: 3.1.2
[error] Xcode is not installed
[success] Android looking great! š
Platform(s)
Android 10
Current Behavior
When I try to call Geolocation.getCurrentPosition(), I always get an error: ālocation unavailableā. Iāve tried this with no options and {enableHighAccuracy: true}.
I have the appropriate permissions set and the code works on PWA and iOS. The app has Location permission while in the foreground and Google Maps can get my location fine.
Expected Behavior
Geolocation.getCurrentPosition() should provide the lat/lng of the current position.
Code Reproduction
edit: basic repo set up here: https://github.com/jonathan-chin/capacitor-geocode-android-example
clicking on the get currentposition button will return location unavailable when running on a Google Pixel 3A on Android 10 through Android Studio.
it seems to have been an existing issue in the past #2854 but I am still experiencing it.
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 7
- Comments: 60 (19 by maintainers)
Iāve reported this issue on google issue tracker https://issuetracker.google.com/issues/198176818
Awesome! š
Are there plans to release an update to Capacitor v2 with the same fix? I see someone has an open PR for it: https://github.com/ionic-team/capacitor/pull/4992 . Thought it might be worth asking since some of us have yet to upgrade to v3 and given the level of severity of the issue. š
For now Iāve manually made the changes in https://github.com/ionic-team/capacitor/pull/4992 to
node_modules/@capacitor/android/capacitor/src/main/java/com/getcapacitor/plugin/Geolocation.javaand used patch-package so we can hotfix our app. We can then remove the patch if the fix lands in Capacitor v2 or when the day comes that we upgrade to v3.Thanks so much!
We have released @capacitor/android 2.5.0 with the fix, but please, update to capacitor 3 as soon as possible, itās not that hard and most fixes wonāt be backported to capacitor 2.
@capacitor/geolocation 1.1.0 is out with a fix
Itās a Google Play Service bug. I factory reset my phone, the problem is not happening.ļ¼Google Play Service v19.5.30ļ¼ Then update Google play Service to newest version (v21.30.16), the problem happened.
We followed these steps to patch (Thanks @KevinKelchen) and had to add an optional step 6 to have it run in Ionic AppFlow:
@capacitor/androidand updateGeolocation.javausing this PRs changes (https://github.com/ionic-team/capacitor/pull/4992/files)npx patch-package @capacitor/androidpackage.jsonwith"postinstall": "patch-package"npm install patch-packageso dependency exists whennpm installis run during Ionic AppFlowpackage.json.npmrcwithunsafe-perm = truewhen using Ionic AppFlow since we canāt use a non-root userthank you so much, it work now
I can confirm that implementing this change to Geolocation.java fixes it for me
Although effectively this is a change in node_modules , so only a temporary solution⦠(for now I am using patch-package)
Iām currently migrating my code to use Ionic Native since I have a tight deadline. Iād love to be able to use 100% Capacitor and am happy to switch back after this gets resolved.
I updated the repo a second time to implement @ionic-native geolocation. this gives me a lat/lng while the capacitor implementation still returns ālocation unavailableā.