Baseflow / flutter-geolocator

Android and iOS Geolocation plugin for Flutter
https://baseflow.com/
MIT License
1.22k stars 626 forks source link

[Bug]: macOS, LOCATION UPDATE FAILURE:Error reason: (null)Error description: The operation couldn’t be completed. (kCLErrorDomain error 0.) #1534

Open DmitrySikorsky opened 1 week ago

DmitrySikorsky commented 1 week ago

Please check the following before submitting a new issue.

Please select affected platform(s)

Steps to reproduce

  1. Use macOS Sonoma (14.5 in my case) on M2 chip.
  2. Download geolocator sample.
  3. Go to system settings, disable and then enable location services (Privacy & Security -> Location).
  4. Run the sample and click on determine location button. Agree to provide permissions.
  5. You will see the "LOCATION UPDATE FAILURE:Error reason: (null)Error description: The operation couldn’t be completed. (kCLErrorDomain error 0.)" in terminal and will have to wait up to 8 minutes to get location.

Expected results

The app should provide location instantly or fast and without errors.

Actual results

The error message is displayed in terminal, but after about 3-5-8 minutes location is determined. Next attempts are instant.

Code sample

Please use the sample from this repository as the code sample.

Screenshots or video

No response

Version

12.0.0

Flutter Doctor output

Doctor output ```console Flutter (Channel stable, 3.22.0, on macOS 14.5 23F79 darwin-arm64, locale en-GB) • Flutter version 3.22.0 on channel stable at /users/dmitrysikorsky/documents/flutter ! Warning: `flutter` on your path resolves to /Users/dmitrysikorsky/Documents/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /users/dmitrysikorsky/documents/flutter. Consider adding /users/dmitrysikorsky/documents/flutter/bin to the front of your path. ! Warning: `dart` on your path resolves to /Users/dmitrysikorsky/Documents/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /users/dmitrysikorsky/documents/flutter. Consider adding /users/dmitrysikorsky/documents/flutter/bin to the front of your path. • Upstream repository https://github.com/flutter/flutter.git • Framework revision 5dcb86f68f (7 weeks ago), 2024-05-09 07:39:20 -0500 • Engine revision f6344b75dc • Dart version 3.4.0 • DevTools version 2.34.3 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades. [✗] Android toolchain - develop for Android devices ✗ Unable to locate Android SDK. Install Android Studio from: https://developer.android.com/studio/index.html On first launch it will assist you in installing the Android SDK components. (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions). If the Android SDK has been installed to a custom location, please use `flutter config --android-sdk` to update to that location. [✓] Xcode - develop for iOS and macOS (Xcode 15.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15E204a • CocoaPods version 1.15.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [!] Android Studio (not installed) • Android Studio not found; download from https://developer.android.com/studio/index.html (or visit https://flutter.dev/docs/get-started/install/macos#android-setup for detailed instructions). [✓] VS Code (version 1.90.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.90.0 [✓] Connected device (3 available) • macOS (desktop) • macos • darwin-arm64 • macOS 14.5 23F79 darwin-arm64 • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin • macOS 14.5 23F79 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 126.0.6478.114 ! Error: Browsing on the local area network for iPhone (Olga) (3). Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac. The device must be opted into Developer Mode to connect wirelessly. (code -27) [✓] Network resources • All expected network resources are available. ! Doctor found issues in 3 categories. ```
ricudis commented 2 days ago

After quite a lot of investigation, I discovered that when running on MacOS, in addition to the usual setup steps, you need to have WIFI enabled in order for your location to be obtained.

Apparently Apple sometimes doesn't use IP geolocationing and resorts to visible SSID geofencing.

You can reliably trigger this by turning WIFI on / off. You don't need to connect to a SSID, just turning on WIFI is enough.

Symptoms :

1) checkPermissions() returns LocationPermission.always

2) isLocationServiceEnabled() returns true

3) Geolocator.getCurrentPosition(desiredAccuracy: LocationAccuracy.medium) hangs until timeout, then returns null

4) An exception is thrown (LOCATION UPDATE FAILURE:Error reason: (null)Error description: The operation couldn’t be completed. (kCLErrorDomain error 0.)).

(tested with MacOS Sonoma 14.5 on a Mac Mini M1)

Perhaps it would be useful to try replicating this and putting some note in the documentation.