I'm using html5 geolocation for my rails app, but when I click on the try it
button the following error appears inside the safari browser console
under the show web inspector console
:
getLocation — localhost:83[blocked] Access to geolocation was blocked over insecure connection to http://localhost:3000.
and here is the code:
<button onclick="getLocation()">Try It</button>
<p id="demo"></p>
<script>
var x = document.getElementById("demo");
function getLocation() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
</script>
The relevant code is taken from Google's Geolocation Demo and run through rails. At present, the geolocation occassionally succeeds through Chrome (~10% of the time), always works almost immediately in opera, works ~80% of the time in Firefox and always fails immediately in Safari. In failing browsers, only Safari returns an error in the console.
Connection denied by Geolocation Setting. The connection was denied because this country is blocked in the Geolocation settings. How do I correct or change this? Community content may not be verified or up-to-date. Learn more. use a VPN ? You can change/turn off your geolocation in the settings under Privacy and Security.
You can change/turn off your geolocation in the settings under Privacy and Security. Go to Permissions and make any changes to Block or Allow based on the website you are accessing. however the website may be using the IP address of your internet service provider to determine your location.
Safari (unlike Chrome and Firefox) does not allow access to geolocation over the HTTP protocol - only HTTPS. Even for localhost. Thanks a lot Apple.
The solution is to either use another browser in development or serve Rails over HTTPS. You can do that by generating a self-signed certificate and setting up the Rails development server (Webrick or Puma) to serve over HTTPS.
Rails 5 defaults to Puma, while earlier versions used Webrick.
The exact approach varies depending on your OS and which server is in use.
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