Jump to content

getCurrentPosition not working in safari or IE11


joshmaxwell
 Share

Recommended Posts

The file at this url contains exactly the code below, and the domain is SSL https://staging13.dgstesting.com/new2.html

<!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

Link to comment
Share on other sites

You probably should check the security settings of each of your browsers. Whenever the website makes a request for the location, the browser asks the user for permission. If this is not happening it's likely that the browser has been configured to reject all location permission requests. Each browser has its own permission setting, it is not shared across browsers.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...