0

EDIT: The symptoms of this problem are inconsistent. Today I tried this again and suddenly it works... sometimes. If I refresh over and over it works about half of the time. If it runs inside an iframe the iframe requires both allow-same-origin and allow-scripts. I can't really be sure about any of this though because it is so inconsistent. Ultimately I decided to go with IP based geolocation simply to avoid the headache.

If anyone can replicate this problem, let me know in the comments. TLDR: This link will display an error in safari and ie11, but not chrome.

The code in question:

<!DOCTYPE html>
<html>
  <head>
    <script>  
        navigator.geolocation.getCurrentPosition(function(position){
                document.body.innerHTML = position.coords.latitude;
        }, function(error){
                document.body.innerHTML = error.message;
        });
    </script>
  </head>
  <body>
  </body>
</html>

The problem: On chrome, edge beta (so basically chrome) and chrome on android, this code will succeed and print your devices latitude to the page. On Safari, safari for ios, and IE11, this will fail with the message "This site does not have permission to use the Geolocation API."

I assume it's not referring to the user granting permission to access location data, but i checked this anyway. Doesn't appear to be the case because it's working in one browser but not another on the same device. In my example, it works in chrome but not ie11 on the same windows 10 computer. I also had a coworker confirm the same thing, it works in chrome but not safari on his mac.

That leaves me thinking it's a domain issue, but why would it work in one browser and not another? After tons of Googling the best answer I can find is that it is an SSL issue, but if you go to https://developers.google.com/maps/documentation/javascript/geolocation you can see that even google.com is facing the same issue. So I think that rules that out. you can even try it on w3schools own site https://www.w3schools.com/html/html5_geolocation.asp

Google of course has no input here because navigator is a product of html5

Yu Zhou
  • 11,532
  • 1
  • 8
  • 22
Josh Maxwell
  • 79
  • 10

1 Answers1

1

I can't reproduce the issue in IE 11. I tested the Google and w3schools links in IE 11 and they asked for permissions to get location and can show the location if I permitted. I also tried the code snippet you providing and it output the position in both IE 11 and Chrome.

Have you unchecked the "Never allow websites to request your physical location" box in IE 11? Besides, I also found a similar thread and you could also refer to the solution in it.

And in your post, it seems that you have found a solution. I suggest that you could also put your solution as an answer and take the best answer as an accepted answer. It can help other community members in future in similar kind of issues.

Yu Zhou
  • 11,532
  • 1
  • 8
  • 22
  • TLDR: Try it in Safari. (I dont have a mac) FULL COMMENT: Yeah suddenly IE11 is working, I could reproduce this issue all all last week and suddenly I can't across multiple computers. However, Safari (and possibly firefox), at least on a Mac, seems to still have the issue. Obviously Safari is modern unlike IE11 so that means the issue still stands, and therefor I would not say I have an answer. Instead I have a work around, which is basically TRY to get geo, and if it fails go for IP, which I should be doing anyway so that's fine, but it still seem ridiculous to me that Safari isn't working. – Josh Maxwell Feb 03 '20 at 17:10
  • "Never allow websites to request your physical location" was greyed out (and unchecked). I think IE11 on a W10 PC turns this feature off, but with a regedit I turned it back on. Didn't help anyway/ – Josh Maxwell Feb 03 '20 at 17:13
  • I don't have a mac too. So I can't try it on Safari. – Yu Zhou Feb 04 '20 at 01:50