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

Geolocation error (kCLError Domain 0) on iOS when no WiFi networks are in range #9342

Open
4 tasks done
binghamchris opened this issue May 16, 2024 · 6 comments
Open
4 tasks done

Comments

@binghamchris
Copy link

binghamchris commented May 16, 2024

Checklist

  • I've looked at the documentation to make sure the behavior isn't documented and expected.
  • I'm sure this is an issue with Leaflet, not with my app or other dependencies (Angular, Cordova, React, etc.).
  • I've searched through the current issues to make sure this hasn't been reported yet.
  • I agree to follow the Code of Conduct that this project adheres to.

Steps to reproduce

This issue occurs naturally only in places where no WiFi networks are in range of your device. To reproduce this issue in places where there are WiFi networks, use the following steps:

  1. On an iOS device, completely disable WiFi in the Settings app.
  2. (Optional) Check in a mapping app, such as Apple Maps or Google Maps, to see that the device is still able to return a geolocation without any detected WiFi networks.
  3. Navigate to a site which uses Leaflet and offers geolocation. Either OpenStreetMap or my project Paddel Buch can serve as examples of this.
  4. Click the geolocation button.
  5. The following error message is displayed: Geolocation error: The operation couldn't be completed. (kCLErrorDomain error O.).

Note that the map is zoomed to the correct location as the error message is displayed. The location marker is also very briefly displayed on the map as the error message comes up.

I've found that this error occurs with enableHighAccuracy set to either true or false, and with watch set to either true or false.

Expected behavior

When geolocation is used on an iOS device in areas where there are no WiFi networks, Leaflet should use the location provided by the device and not display an error message.

I'm afraid I don't have an Android device to test with to see if this issue occurs on other platforms.

Current behavior

Leaflet seems to be handling the geolocation returned by iOS when no WiFi networks are in range incorrectly. I base this on the fact that the map is zoomed to the correct bounds and the location maker is briefly displayed, indicating that Leaflet received a location and processed it correctly initially, and only after this throws an error.

I've tried to work out where in the code this is happening, without success I'm afraid.

For my project this is a very problematic issue as Paddel Buch is intended to support paddle sports participants on the Swiss lakes, and naturally you don't usually find WiFi networks in the middle of a lake!

Minimal example reproducing the issue

No response

Environment

  • Leaflet version: 1.9.3 and 1.9.4
  • Browser (with version): iOS Safari 17.4 and 17.5
  • OS/Platform (with version): iOS 17.4 and 17.5
@binghamchris binghamchris added bug needs triage Triage pending labels May 16, 2024
@IvanSanchez
Copy link
Member

@IvanSanchez IvanSanchez added needs more info and removed needs triage Triage pending labels May 16, 2024
@binghamchris
Copy link
Author

Does the same error show up at https://developer.mozilla.org/en-US/docs/Web/API/Geolocation_API/Using_the_Geolocation_API#examples ?

No, on this page the correct lat/lon coordinates are displayed with no error messages when WiFi is disabled.

@binghamchris
Copy link
Author

I've been able to get a quick test of this on a Samsung Android 14 device, and with WiFi switched off geolocation worked without an error message with Leaflet 1.9.4.

Seems like this issue might be limited to iOS devices.

@Malvoz Malvoz added the ios label May 19, 2024
@binghamchris
Copy link
Author

I notice the needs more info label is still attached to this issue.
Is there any more information I can try to get to help with this please?

@IvanSanchez
Copy link
Member

It's more like "need spare time and also an iPhone and an iMac which I don't have".

@binghamchris By any chance would you be able to provide an error stack? Attach a desktop Safari as a debugger (and the works) in order to put breakpoints in the javascript code.

The Leaflet geolocation code is pretty barebones and just calls the geolocation API a couple times. It's necessary to see how it runs compared to other geolocation examples.

@binghamchris
Copy link
Author

binghamchris commented May 25, 2024

OK, I've had a go at this @IvanSanchez. Not being a JS developer I'm unsure if I've got the right info for you, so please let me know if there's more you need :)

With WiFi switched off on the iPhone, I put a breakpoint on the locate function and stepped through until the error message came up in the variables:
Safari Debug- Leaflet Geolocate Error

When this stage is reached, which is right before the error message is displayed to the user on the iPhone, there's two things I notice:

  1. On the iPhone the map is zoomed to the correct area, with the location marker in the right place (my actual location) and the location accuracy circle showing a wide accuracy circle (roughly 1.5km diameter).
  2. The this._lastCenter variable has the lat/lon coordinates of my actual location (redacted in the screenshot).

Does this help please?

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

No branches or pull requests

3 participants