Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Origin does not have permission to use Geolocation service -- even over HTTPS

I have a web page that uses HTML5 geolocation over HTTPS. It works a-okay on desktop browsers. On iOS Safari, however, I get the error that "Origin does not have permission to use Geolocation service". I have ensured that everything on the page loads via HTTPS -- every image, every script, and all other assets are showing HTTPS in Chrome dev tools. Nonetheless, geolocation returns the error.

Here's some of my JavaScript:

if ("geolocation" in navigator) {
    navigator.geolocation.getCurrentPosition(function (position) {
        // Do stuff with the geo data...
    }, function(error) {
        // I always end up here on iOS Safari.
        alert(error.code + ": " + error.message);
    });
} 
else {
    $("#search-results").append("Location is unavailable in this browser.");
}

What have I missed?

More info: I just grabbed the code from this W3 Schools example, which works perfectly in my iOS Safari, and pasted it on my site. It did not work. I still receive no prompt to allow geolocation on my site. I've cleared browser cache and reset location warnings in Settings to no avail.

like image 649
mrcoulson Avatar asked May 08 '17 20:05

mrcoulson


1 Answers

I had the same problem and it is because of new standards for the Golocation API in Chrome (and Safari):

Chrome no longer supports obtaining the user's location using the HTML5 Geolocation API from pages delivered by non-secure connections.

The only solution is to host from HTTPS and remove all HTTP requests from third parties. Check your network tab in developer mode to filter out HTTP calls, this also includes images (which was the trouble in my case).

You can read more here: Geolocation API Removed from Unsecured Origins.

like image 145
Mathias Mølgaard Avatar answered Oct 17 '22 22:10

Mathias Mølgaard