Skip to content
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

UserLocation does not use high accuracy on Android 12 #1795

Closed
benjamin-sweney opened this issue Mar 17, 2022 · 5 comments
Closed

UserLocation does not use high accuracy on Android 12 #1795

benjamin-sweney opened this issue Mar 17, 2022 · 5 comments

Comments

@benjamin-sweney
Copy link

Describe the bug
After users have upgraded to Android 12 the UserLocation component no longer appears to use high accuracy mode. This is indicated by the users location darting around (as opposed to being true to their actual location) and the location status icon is no longer shown. On Android 11 the location status icon was shown regardless.

Using React Native Geolocation with a watch and high accuracy mode turned on corrects to the expected behaviour showing an accurate location and the location status icon.

To Reproduce
Use a UserLocation component on any Android 12 device. I have been using a S20 FE and an S21 to confirm (Android 12 vs still on Android 11)

Example:

import React from 'react';
import {
  MapView,
  ShapeSource,
  LineLayer,
  Camera,
  UserLocation,
} from '@rnmapbox/maps';

class BugReportExample extends React.Component {
  render() {
    return (
      <MapView style={{flex: 1}}>
        <UserLocation />
      </MapView>
    );
  }
}

Expected behavior
The users location is shown correctly and the location status icon is shown indicating use of high accuracy location.

Actual behavior
Users location darts around and no location status icon is shown.

Screenshots

Versions (please complete the following information):

  • Platform: Android
  • Platform OS: Android 12
  • Device: Android S20 FE
  • Emulator/ Simulator: no
  • Dev OS: MacOS 12.1
  • @rnmapbox/maps Version 8.4.0
  • Mapbox GL version 9.7.1
  • React Native Version 0.66.4

Additional context
N/A

@RobertSasak
Copy link
Contributor

Good job spotting that is the issue that occurs on Android 12. I think the solution is describe here https://developer.android.com/training/location/permissions#approximate-request so more of us can read it up.

@RobertSasak
Copy link
Contributor

In my case I call requestAndroidLocationPermissions which implementaion is here

maps/javascript/index.js

Lines 45 to 48 in dda13db

const res = await PermissionsAndroid.requestMultiple([
PermissionsAndroid.PERMISSIONS.ACCESS_FINE_LOCATION,
PermissionsAndroid.PERMISSIONS.ACCESS_COARSE_LOCATION,
]);

It ask for both Coarse and Fine locations. On Android 11 and below user is shown a dialog for grating location permission. On Android 12 user in addition can decide also to give Precise or Approximate location.

As written in the https://developer.android.com/training/location/permissions#approximate-request app should always request both Fine and Coarse permissions together. There is no way to force user to only grant Fine precision. However user can be informed about his/her decision and ask to upgrade to Precise. https://developer.android.com/training/location/permissions#upgrade-to-precise

This can be done by requesting again for both Coarse and Fine location again.

As I don't have a Android 12 telephone at the moment, @benjamin-sweney can you please confirm this behaviour?
Can you also verify that you can change granted permission in the telephone settings under app settings?
Does switching to Precise permission solve the issue?

@hkfreddy
Copy link

I have the same issue on Android 12
@RobertSasak
Both PERMISSIONS.ACCESS_FINE_LOCATION and PERMISSIONS.ACCESS_COARSE_LOCATION are granted for my app
(I can see the Precise permission is on in the phone setting) but seems the problem is still here

@benjamin-sweney
Copy link
Author

@RobertSasak I use the MapboxGL.requestAndroidLocationPermissions(); function on boot of my application to call the correct permissions. This includes both required permission calls as needed on Android 12.

@RobertSasak
Copy link
Contributor

Solution is described mapbox/mapbox-gl-native-android#730 and https://docs.mapbox.com/android/maps/guides/user-location/#location-provider
TLDR add following into build.gradle

implementation("com.google.android.gms:play-services-location:19.0.1")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants