question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

bug: Geolocation on Android always returning 'location unavailable'

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:7
  • Comments:60 (19 by maintainers)

github_iconTop GitHub Comments

12reactions
jcesarmobilecommented, Aug 31, 2021

I’ve reported this issue on google issue tracker https://issuetracker.google.com/issues/198176818

8reactions
KevinKelchencommented, Sep 3, 2021

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!

Read more comments on GitHub >

github_iconTop Results From Across the Web

GeoLocation returns “Location Unavailable” for Android 11 ...
The steps we just applied using patch-package: Access @capacitor/android and update Geolocation. java using this PRs changes (https://github. ...
Read more >
GeoLocation returns "Location Unavailable" for Android 11
I have an application Ionic Capacitor Angular that is simply getting the GeoLocation and displaying the lat lng on screen
Read more >
How to fix a location unavailable error in the Android device ...
Just go to settings, then click location. Turn it on and agree to Improve location accuracy by this you can fix location unavailable...
Read more >
Troubleshoot phone location for Routines - Google Nest Help
Note: If your device runs a version of the Android OS earlier than 4.3, it may not have a setting option for Location...
Read more >
Geolocation API not working in Chrome on Android - Monorail
Settings > Content settings > Website settings > jsbin.com > Location access is checked, i.e. Chrome is allowed to get location. And it...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found