HTML Geolocation API does not work properly on some iOS devices

I created a PWA that requires access to users' geolocation to perform a certain action in the system. The correct operation would be the user opens the application, and then the operating system prompts them to allow sharing their exact location with the PWA. However, this is not happening with a few users who have iPhone 11 or XR.

I tested it on iPhones 14, 13, 11 Pro, and even iPhone 6, and it works as expected. I directly spoke with a user who was experiencing the problem and conducted some tests.

  1. I checked if location access was allowed in the settings.
  2. I verified if Safari was accepting with the option to always ask selected.
  3. In the settings of my system's website, I checked if location access was allowed with the option to always ask chosen.
  4. We changed all prompting options to allow.
  5. We opened the following site https://whatpwacando.today/ and found that geolocation was also not possible.

Everything indicates that the issue lies with these users' phones; however, other geolocation methods work fine, as other geolocation apps function properly. This leads me to think that it might be a problem with Safari not working properly with the HTML Geolocation API.

I'm not sure if there are any more advanced settings that could help or if anyone else has encountered this issue.

We're also experiencing the same issues on iPhone 15.

Despite changing the website settings to always allow the location, we still get a GeolocationPositionError with code 1 "user denied geolocation"

Nevermind. The guide from https://whatpwacando.today/geolocation was pointing out the issue with location permissions for Safari

In my case, Safari (iOS or Mac OS) which affects PWAs, there is inconsistency between Safari's location permission setting and the actual geolocation permission state value in the navigator object.

  • If the permission setting is "Allow" then navigator.permissions.query({name: "geolocation"}) state is always granted. This is consistent and working well.

  • If the permission setting is "Deny" then navigator.permissions.query({name: "geolocation"}) state is prompt instead of denied. When asking for user's location navigator.geolocation.getCurrentPosition((geo) => console.log(geo), (error) => console.log(error)) returns the error "User denied Geolocation" but the navigator object's permission is still prompt.

  • If the permission setting is "Ask" then navigator.permissions.query({name: "geolocation"}) state is is "prompt". When asking for user's location navigator.geolocation.getCurrentPosition((geo) => console.log(geo), (error) => console.log(error)). Now there are three possibilities here:

  1. if the user selects "Deny" returns the error "User denied Geolocation" but the navigator object's permission is still prompt. If is asked for user's location again, returns the error without prompting the user, but still the navigator object's geolocation permission state is prompt.
  2. if the user selects "Allow" without checking "Remember for one day" returns the location but the navigator object's geolocation permission state is prompt. If is asked for user's location again, returns the location without prompting the user, but still the navigator object's permission is prompt.
  3. if the user selects "Allow" and checks "Remember for one day", returns the location but the navigator object's geolocation permission state is granted. No problem here.

It's extremely difficult to know what could happen by checking the navigator object's geolocation permission state. There are so many different cases in which the state is prompt, that it is very difficult to handle them all. However, other browsers in Mac OS manage the permissions well, but not in iOS though, because they all depend on iOS/Safari settings.

Honestly, it is a nightmare to handle geolocation permissions in Safari. Curiously, the camera permission doesn't have those problems.

I hope Apple will fix this soon.

HTML Geolocation API does not work properly on some iOS devices
 
 
Q