react-native-geolocation icon indicating copy to clipboard operation
react-native-geolocation copied to clipboard

Error on Android when only giving approximate (coarse) location

Open ampopdev opened this issue 1 year ago • 1 comments

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: - DriverKit 23.4 - iOS 17.4 - macOS 14.4 - tvOS 17.4 - visionOS 1.1 - watchOS 10.4 Android SDK: Not Found IDEs: Android Studio: 2023.2 AI-232.10227.8.2321.11479570 Xcode: version: 15.3/15E204a path: /usr/bin/xcodebuild Languages: Java: version: 17.0.9 path: /usr/bin/javac Ruby: version: 2.6.10 path: /usr/bin/ruby npmPackages: "@react-native-community/cli": Not Found react: installed: 18.2.0 wanted: 18.2.0 react-native: installed: 0.72.11 wanted: 0.72.11 react-native-macos: Not Found npmGlobalPackages: "react-native": Not Found Android: hermesEnabled: true newArchEnabled: false iOS: hermesEnabled: false newArchEnabled: false

Platforms

Android

Versions

  • Android: API 33
  • react-native-geolocation: 3.2.1
  • react-native: 0.72.11
  • react: 18.2.0

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.

ampopdev avatar May 21 '24 08:05 ampopdev

CleanShot 2024-05-27 at 07 35 32@2x

Did you try lower version?

kieuhuynhdev avatar May 27 '24 00:05 kieuhuynhdev