-
Notifications
You must be signed in to change notification settings - Fork 1k
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 on Android always returning 'location unavailable' #4962
Comments
This issue may need more information before it can be addressed. In particular, it will need a reliable Code Reproduction that demonstrates the issue. Please see the Contributing Guide for how to create a Code Reproduction. Thanks! |
@jcesarmobile @Ionitron just updated with a bare minimum repo. |
I've been using this plugin without any problems for weeks while developing my app. I've just updated all packages to the latest versions and now I am also experiencing this issue. Goes straight to error after giving the app permission. No error code or anything just 'location unavailable' Ionic 6.17.0 I'm getting the same thing on the emulator (with play store) as well as on my device. Web is fine. Android build now generated the following warnings, not sure if they are relevant: AGPBI: {"kind":"warning","text":"Using flatDirs should be avoided because it doesn't support any meta-data formats.\nCurrently detected usages:\n- repository flatDir used in: project ':app', project ':capacitor-cordova-android-plugins'","sources":[{}]} Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0. |
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'. |
Having gone into Tools > SDK Tools in Android Studio and ticking the box for Google Play services in the SDK Tools tab, it works in the emulator now. Setting the location doesn't work, but at least do get a position. Still can't get it to work on my Android device which is logged in to Play Store. Seems to be some disconnect between Play Services and Capacitor / Android Studio. |
Native Geolocation works fine so am sticking with that! |
I have the same problem ! |
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 can't reproduce on the provided app, but buttons are working and returning locations. Tested on Android 9 and Android 11 devices. the cordova plugin uses the WebView location, so it's no different from using
|
@jcesarmobile I tested on a physical phone by running it through Android Studio. the phone is: I've also run in in the Android simulator: let me know if you need more info |
Can you open |
I'm seeing this issue on a Pixel 5 and Galaxy Tab A both running Android 11. |
it seems I'm getting it here:
|
And what happens if you remove the whole |
@jcesarmobile removing the function makes it work. I got lat/lng, altitude, speed, etc. |
🤔 that's really weird, why would onLocationAvailability fire and say it's not available but return a location if you ignore it? |
@jcesarmobile so I went off of this: if I push the app via Android studio (with onLocationAvailability still in), then reset my phone, I get results. if I spam the button, I will sometimes get location unavailable, but only like 1/30 times and the following key press works just fine (and when I say spam, I mean spam). however, when I background the app and come back to it, I get location unavalable. BUT if I call the ionic native version once, I get results from capacitor for the next 4-5 keypresses. I can do this reliably. |
Yeah, I also saw that thread, but looked like a device bug. I still can't reproduce, even backgrounding the app. And sadly removing the Can you replace the whole
|
I'm getting 4 compile errors: cannot find symbol class OnCompleteListener cannot find symbol class Task cannot find symbol class NonNull method does not override or implement a method from a supertype |
You might need to manually add this imports (sometimes Android Studio doesn't add them by default)
or putting the cursor over the unrecognized symbol and pressing alt+Intro can also import it |
@jcesarmobile sorry, I don't use Android Studio much; I have barely coded in Java in the last 15 years. the new function seems to work well. I have not gotten a location unavailable ever during the 30 seconds I spammed the button. this may be a fix! what is different? |
I can confirm that within the last week or so this plugin is reporting "location unavailable" on android.
|
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) |
Don't worry, Android Studio can be annoying sometimes. Thanks for testing! It uses a new method for getting a single location (at the moment the plugin starts tracking location and stops it when it get the first result). It was introduced in play-services-location 17.1.0 and is supposed to handle this kind of errors/problems better. On the other hand, it doesn't allow to configure the timeout, which could be considered a breaking change in the plugin, so we don't know when we would be able to do a new release with the fix. |
looks like Google didn't remove 21.30.16 from play store as I just got it on my device |
My Google Play Services version is 21.33.12 and I am still having the issue. |
I've reported this issue on google issue tracker |
I have been testing on an android 7 and using native ionic Location accuracy I have been able to change the precision to the user and this way it works, but the problem comes with Android 11, there is no way to make it work |
I have been tesing on GalaxyA32 (Android 11) the Geolocation plugin |
Same issue... Temporarily solved by commenting out these lines in Geolocation.java if (!availability.isLocationAvailable()) { |
@capacitor/geolocation 1.1.0 is out with a fix |
Awesome! 😀 Are there plans to release an update to Capacitor v2 with the same fix? I see someone has an open PR for it: #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 #4992 to Thanks so much! |
@KevinKelchen |
It’s not |
thank you so much, it work now |
We followed these steps to patch (Thanks @KevinKelchen) and had to add an optional step 6 to have it run in Ionic AppFlow:
|
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. |
JFYI: looks like Google has updated Play-Services. |
not working for me with that version |
strange... |
For our users, it appears to be intermittent. One user reports 80% fail 20% success on getting a GPS fix. |
For our users, we have reports from 8th August, and 9th of september that location did not work for them. I can emulate a Pixel 2 API 28 that works fine in Android Studio. The user on 8th of August has Android 10 on a Galaxy A41 and the user on 9th of September has Android 11 on a Oneplus Pro 9 5G. The app we released worked on release, and has since seen reports of failure on the GPS. We use the Geolocation from capacitor/core and the manifest has the permissions included as the documentation says. Getting the play service versions has not been possible. Will try upgrading to 2.5.0 as @krabien said, and will see if that fixes it for us aswell |
capacitor/android 2.5 ...does seem to fix the issue on an OnePlus 6, Android 10. But on an emulated Pixel 3 API 30, while Geolocation.getCurrentPosition does get called, it never receives a result. Not even a 'location unavailable' like previously. |
@jcesarmobile how's this coming along? Any word from Google on sorting it out? I'm reluctant to have to submit new builds with updated Capacitor plugins if its not a certainty that it'll work still. |
Google said they reverted the changes last week and should work again, but play services updates takes time and not everybody gets them at the same time. I would recommend updating as they don't recommend relying in |
Is there any official statement from google i can send to my users? |
No official statement as far as I know, only a comment on the issue I reported |
Hi I get this 'location unavailable' issue everytime I try to get my location on my phone (pixel 4a, google play services 22.33.16) for the first 5 minutes or so. Then eventually I'm able to get a location. I'm trying to make it so that I don't have to wait 5-10 minutes for a location. I'm not really able to understand java but I'm getting "location unavailable" from this code block. I know because I changed the error message so I knew it was coming from here:
I tried following the issuetracker link and using the code from the #105 post about the PRIORITY_HIGH_ACCURACY, and copied it in and got a lot of errors. I also tried the solution of downgrading my gradle version but that gives me errors. Any recommendations for what I should do? |
We're having the same issue. All was fine a week or so ago. I'm assuming it's a Google Play Service bug, as it has been previously, and we just have to wait for a fix. |
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. |
Bug Report
Capacitor Version
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 returnlocation 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.
The text was updated successfully, but these errors were encountered: