michalchudziak / react-native-geolocation

Geolocation APIs for React Native
MIT License
1.27k stars 219 forks source link

Error on Android when only giving approximate (coarse) location #315

Open ampopdev opened 1 month ago

ampopdev commented 1 month ago

Environment

System: OS: macOS 14.3.1 CPU: (10) arm64 Apple M1 Pro Memory: 111.42 MB / 16.00 GB Shell: version: "5.9" path: /bin/zsh Binaries: Node: version: 22.1.0 path: /opt/homebrew/bin/node Yarn: version: 1.22.22 path: ~/.nvm/versions/node/v21.7.1/bin/yarn npm: version: 10.7.0 path: /opt/homebrew/bin/npm Watchman: version: 2024.05.06.00 path: /opt/homebrew/bin/watchman Managers: CocoaPods: version: 1.15.2 path: /usr/local/bin/pod SDKs: iOS SDK: Platforms:

Platforms

Android

Versions

Description

When giving only approximate location permission (ACCESS_COARSE_LOCATION) getCurrentPosition returns error:

{"ACTIVITY_NULL": 4, "PERMISSION_DENIED": 1, "POSITION_UNAVAILABLE": 2, "TIMEOUT": 3, "code": 3, "message": "Location request timed out"}

Reproducible Demo

Request permission with react-native-permissions:

import { PERMISSIONS, requestMultiple } from 'react-native-permissions';

await requestMultiple([
      // Requesting both as doc https://developer.android.com/develop/sensors-and-location/location/permissions#approximate-request
      PERMISSIONS.ANDROID.ACCESS_COARSE_LOCATION,
      PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION,
    ]);
const result =
        multipleResult?.[PERMISSIONS.ANDROID.ACCESS_COARSE_LOCATION];
console.log(`Did grant at least approx location: ${result === 'granted'}`) // Result will be granted for either ACCESS_FINE_LOCATION or ACCESS_COARSE_LOCATION

Get location:

      import Geolocation from '@react-native-community/geolocation';

      Geolocation.getCurrentPosition(
        position => {
          console.log('position', position);
        },
        error => {
          console.log('error', error);
        },
        { enableHighAccuracy: true, timeout: 15000, maximumAge: 10000 },
      );

Tried passing enableHighAccuracy: false, but didn't help. If ACCESS_FINE_LOCATION permission is granted, then getCurrentPosition returns the position correctly.

Anhunghezo commented 1 month ago
CleanShot 2024-05-27 at 07 35 32@2x

Did you try lower version?