michalchudziak / react-native-geolocation

Geolocation APIs for React Native
MIT License
1.28k stars 220 forks source link

getCurrentPosition issue with "enableHighAccuracy" option on iOS #235

Open Bucci83 opened 1 year ago

Bucci83 commented 1 year ago

Environment

System: OS: macOS 12.5.1 CPU: (8) arm64 Apple M1 Memory: 166.30 MB / 8.00 GB Shell: 5.8.1 - /bin/zsh Binaries: Node: 16.15.0 - /usr/local/bin/node Yarn: Not Found npm: 8.5.5 - /usr/local/bin/npm Watchman: 2022.11.28.00 - /opt/homebrew/bin/watchman Managers: CocoaPods: 1.11.3 - /opt/homebrew/bin/pod SDKs: iOS SDK: Platforms: DriverKit 22.1, iOS 16.1, macOS 13.0, tvOS 16.1, watchOS 9.1 Android SDK: Not Found IDEs: Android Studio: 2021.2 AI-212.5712.43.2112.8609683 Xcode: 14.1/14B47b - /usr/bin/xcodebuild Languages: Java: 11.0.16 - /usr/bin/javac npmPackages: @react-native-community/cli: Not Found react: 17.0.2 => 17.0.2 react-native: 0.67.2 => 0.67.2 react-native-macos: Not Found npmGlobalPackages: react-native: Not Found

Platforms

iOS

Versions

Description

subsecuent calls to Geolocation.getCurrentPosition don't work (doesn't return "info" or "error") if invoked more than once with option set to "enableHighAccuracy:true"

Reproducible Demo

1.- call the first Geolocation.getCurrentPosition( (pos) => { console.log('setting Origin', pos); }, (error) => {console.log('GetCurrentPosition Error', JSON.stringify(error));}, { enableHighAccuracy: true } ); from any component inside App (it can be within a useEffect hook) 2.- create a second component that you can invoke at will (button perhaps) 3.- create another instance of Geolocation.getCurrentPosition( (pos) => { console.log('setting Origin', pos); }, (error) => {console.log('GetCurrentPosition Error', JSON.stringify(error));}, { enableHighAccuracy: true } ); and invoke it using the button or component you just created. 4.- I'm not able to see the second "console.log" output 5.- If I remove option " { enableHighAccuracy: true }" from step 3, the code executes correctly and I see the coordinates

***this only fails with iOS, it works as expected on Android

insanebear commented 1 year ago

@Bucci83 Could you share how you did use getCurrentPosition() for Android? As mentioned in #170, I am struggling with using this function for Android, but it seems you do not have the problem. Maybe the my environment is the cause of the problem, however, it would be appreciated if you give me any advice.

{enableHighAccuracy: true, timeout: 2000, maximumAge: 10000},

with this, I got error code '3' that Location request timed out. I've tried multiple variation even deleting the line. Only thing I could resolve this was deleting the line and setting my device Location mode in settings to High accuracy (GPS and networks).

"@react-native-community/geolocation": "3.0.5"
"react": "18.2.0"
"react-native": "0.71.2"
Android SDK: 33
Bucci83 commented 1 year ago

Hello, I've encountered multiple problems when working with location and different android versions. Currently I have my app working with location on Android 9,10,11 and 12.

could you specify which android version are you using and also share the permission from AndroidManifest.xml?

insanebear commented 1 year ago

Thanks for the reply :)

Permissions that my project has:

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>    
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>

My Android emulator version is 31. Since I couldn't find a solution, I tried react-native-geolocation-service now, and haven't tried on different version with this library yet.

I am new to the React Native, so it is little vague where to check. If there's anything I should look up, please let me know.