bug: Geolocation on Android always returning 'location unavailable'
See original GitHub issueBug 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.
Issue Analytics
- State:
- Created 2 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.java
and 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!