iOS and macOS don't give you the user's location if they don't allow it or if the system can't trust you. So:
– First (Probably your answer)
It works with the exact code you entered ONLY IF the host uses https . This is why the permission notification is not displayed due to your comment on the answer below.
Remember that if you do not use https it will be stuck for about a minute and then return an error of authentication failure. Use error to check that:
navigator.geolocation.getCurrentPosition (success, error, options) ]> Safari. This is not the standard option, but maybe you accidentally changed it. So don't worry about the users if this was the problem. If you use Chrome or other third-party browsers, go to the settings and check if the location is available. It is not there by default and is shown only if the location wanted at least once.
If you are going to load your web site in an app using
webViewmake sure to add permission description descriptions to info.plist files. Add
NSLocationUsageDescriptionas your needs.
For the sake of completeness, on iOS13, you cannot always ] permission. But this is not the point here and the point is that you need to get the necessary permissions once before you need to get the location from the GPS, or that it doesn't work at all.