cordova-plugin-geolocation icon indicating copy to clipboard operation
cordova-plugin-geolocation copied to clipboard

!important Android 12 new approximate location and precise location

Open bhandaribhumin opened this issue 3 years ago • 3 comments

Feature Request

precise location work expectedly but when user select approximate location got error

getCurrentPosition() :

PositionError {code: 1, message: "Illegal Access"}	
code: 1	
message: "Illegal Access"	
__proto__: Object

Motivation Behind Feature

should solve current position coords.

It will requested both permission : Screenshot: 1 user need to choose approximate location or precise location from popup

Screenshot 2021-09-20 at 11 33 56 AM

Screenshot: 2 expected behaviour only view precise location popup

Screenshot 2021-09-20 at 11 36 30 AM

Feature Description

Android BETA change log:

https://developer.android.com/about/versions/12/approximate-location#user-choice-approximate-precise

Alternatives or Workarounds

Not found workaround yet but observe some points:

New location changes might need fixes from both ts and plugin side Plugin Changes : Handle Fine location not requested, send a new message TS Changes : Handle this updated message from plugin

bhandaribhumin avatar Sep 20 '21 05:09 bhandaribhumin

I believe this plugin is already compatible. It seems like if you request FINE location, then starting API 31, you must also request COARSE permission at the same time.

If your app targets Android 12 and you request the ACCESS_FINE_LOCATION permission, you must also request the ACCESS_COARSE_LOCATION permission. You must include both permissions in a single runtime request. If you try to request only ACCESS_FINE_LOCATION, the system ignores the request and logs the following error message in Logcat: ACCESS_FINE_LOCATION must be requested with ACCESS_COARSE_LOCATION.

The reason why I believe this plugin is already compatible is because we old an array containing both of these permissions here:

https://github.com/apache/cordova-plugin-geolocation/blob/8be9229c44a4a00391a8e1be832758a80fbd5b4c/src/android/Geolocation.java#L41

And when requesting:

https://github.com/apache/cordova-plugin-geolocation/blob/8be9229c44a4a00391a8e1be832758a80fbd5b4c/src/android/Geolocation.java#L100-L103

OR

https://github.com/apache/cordova-plugin-geolocation/blob/8be9229c44a4a00391a8e1be832758a80fbd5b4c/src/android/Geolocation.java#L49-L57

However, the issue with coarse only not working is probably due to the fact that it appears that if any of the requested permissions are denied, then we treat the entire prompt as a denial:

https://github.com/apache/cordova-plugin-geolocation/blob/8be9229c44a4a00391a8e1be832758a80fbd5b4c/src/android/Geolocation.java#L64-L82

This is obviously problematic. I think it should only throw an error if highAccuracy was requested, but FINE location is not granted.

breautek avatar Sep 20 '21 15:09 breautek

@breautek Thanks for the observation I already try to debugging the code but ACCESS_COARSE_LOCATION failed all the time. Found valid issue on beta and it is not fixed yet. Here is the issue link google-issuetracker.

bhandaribhumin avatar Sep 21 '21 05:09 bhandaribhumin

I think the plugin behavior should be changed to consider that the permission has been granted if on Android 12 and only coarse permission was granted, or at least if highAccuracy is false.

But sadly there is a bug on the WebView that still won't get location in some cases even if we consider it as granted https://bugs.chromium.org/p/chromium/issues/detail?id=1269362

jcesarmobile avatar Dec 02 '21 11:12 jcesarmobile

This is now resolved by merging of PR #250

dpa99c avatar Oct 18 '22 13:10 dpa99c