-
Notifications
You must be signed in to change notification settings - Fork 663
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
Geolocation working on android 13,14 even 8 but not on android 12 function does not call no error in console #273
Comments
i Forget to mention even in android 12 it asked for location permission every thing seems to be fine regarding permission |
Are you requesting FINE or COARSE location? (e.g. do you have high accuracy enabled or disabled?) Android 12 has a known issue where requesting coarse location doesn't work as expected and instead location requests will timeout. |
const coordinates = await capacitorgeolocation.getCurrentPosition({ |
My androidmanifest
|
Sounds like you're hitting the android bug that I linked earlier. I think the only known workaround is to request high accuracy location (which translates to FINE location natively). e.g.
When If you don't actually need FINE location, then perhaps it might be worth only enabling it on Android 12 devices. This comment suggest that the issue is believed to be fixed but it will require an Android OS update and whether that update is available may be subjected to your carrier. |
So you suggesting enableHighAccuracy:true will resolve the issue on android 12? |
enableHighAccuracy:true |
Can you confirm your device location settings? Settings -> Location -> Location Services Google Location Accuracy should be enabled, otherwise high accuracy / FINE location will not work. Additionally, the app permission should have Precise enabled: Settings -> Location -> App location permissions -> Your Application Ensure location access is enabled with precise location. If either The app permissions will be set by the user on the first time they use your app, but it's possible they disallow precise permission on the permission prompt which will trigger the android 12 bug. Google Location Accuracy is a user setting that can't be programmatically controlled, the user must enable it to enable high accuracy location. Usually it's enabled by default from factory. |
ok i ll update you regarding that tommorow |
@breautek I'm running into the same issue and was wondering if the Android 12 bug affects all cordova builds with cordova Android 12.0.1 platforms? |
I believe so, https://issues.chromium.org/issues/40205003 isn't fully addressed yet it seems. Cordova doesn't actually have an implementation of geolocation for android. It relies on the system webview implementation. So it affects all cordova platforms. It sounds like there is a fix available but you would be relying on users to update their devices, and sometimes carriers don't deliver AOSP updates, which unfortunately means users will be stuck on a bugged version.
The ticket is still open, I think they are looking to find a solution in the system webview since it got migrated. If they patch a workaround in the webview then that update should make it to all users receiving updates from Google Play Store. Another potential workaround is using a plugin that implements native geolocation APIs. Don't really know of any that I can vouch for but I'd imagine most native implementations would generally make use of Google's Fuse location APIs, which will tie your app to Google Play services, e.g. your app will only work on Google-enabled devices. EDIT:
Just caught this... I believe the aforementioned bug only applies Android 12, aka API 31... Not related to Cordova-Android. If you're experiencing this on Android 14/API 34 then you might be experiencing something different. |
@breautek Thank you for your detailed response. |
hello, i am not getting any errors but my android cordova app using this plugin is consistently returning google headquarters in silicon valley. any idea why this might be? oh, this is in the emulator on my mac. my friends android phone puts him Pakistan consistently. This cordova app is built with Android SK 34 and latest 5.0.0 version of the plugin. And, we've used high accuracy as well. The iOS version of this plugin functions correctly. Thank you. |
Hello breautek, Not exactly sure what has changed. |
Cordova doesn't implement any actual geolocation code. What it does do is hook into the webview permission request to request location permissions when necessary. This means geolocation behaviour may change depending on the webview version. It also means that Cordova doesn't have control over geolocation settings at the native level, or influence how it responds to geolocation events. The implementation provided is the exact same implementation found in a standard browser. So first I'd double check that you're fully updated with the If your issue only presents itself with Android 12 devices, then you're likely experiencing https://issues.chromium.org/issues/40205003 (This is the issue that requesting high accuracy is supposedly a workaround). Star the issue so that Google can gauge impact and prioritize appropriately. If your issue is occurring on devices other than Android 12, or is occurring while high accuracy is being requested (and accepted by the end user) then consider giving my blog post on understanding geolocation accuracy and to attempt to rule out environmental factors. Key takeaways are:
If your still finding that your issue persists in "ideal" geolocation conditions then you'll likely need to raise an issue against chromium, see here for their reporting guidelines. This issue is open because https://issues.chromium.org/issues/40205003 is still open. |
Thank you for the reply. |
Google Play Services != Google Play store. Google Play Services is service for Google APIs which depending on the underlying geolocation implementation being used might use Google APIs (The Fused Location Provider API). I do not know what geolocation implementation the browser actually uses, I'm just making an educated guess since the webview is a Google product.
Just another idea that you can check/confirm... I would confirm that your If it's explicitly set to something other than 0, I'd consider testing with
Just to point this out there in case if it isn't obvious, this suggest that the API believes it is working as intended. You should also check the So if the device is clearly not in Pakistan but the true location is within the Reasons for high-value accuracy readings (which suggest that the point is not accurate) will include environmental factors out of your control, but if you're also seeing very high accuracy readings (like 1000m+) then it may also suggest that the |
Bug Report
Problem
What is expected to happen?
Geolocation should give current location in all android devices
What does actually happen?
but it is working in many devices except android 12 there is no error msg at all function does not even call
Information
Command or Code
this.geolocation.getCurrentPosition().then(async (resp:any) => {
Environment, Platform, Device
Android 12 ionic capacitor
Version information
Checklist
The text was updated successfully, but these errors were encountered: