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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With