Post

Replies

Boosts

Views

Activity

Reply to HTML Geolocation API does not work properly on some iOS devices
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: 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. 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. 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.
Oct ’24