mshwf
mshwf

Reputation: 7449

How can I enable geolocation in Google chrome?

I just found that getCurrentPosition() is deprecated from Google Chrome for insecure origins, they are just allowing HTTPS. But I'm trying to run this html file on my machine which to my knowledge is supposed to be secure.

Example from w3school

<p>Click the button to get your coordinates.</p>

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

</body>
</html>

but that doesn't show my current location, if that means that chrome see my local machine as an insecure origin, Is there any way to change that?

Upvotes: 1

Views: 2209

Answers (1)

Manuel
Manuel

Reputation: 337

Yes there is. According to the documentation you can start the browser with a command line flag or use https for the connection.

The command line flag is for debugging and testing purpose and the https connection is for production use:

chrome --unsafely-treat-insecure-origin-as-secure="http://exmaple.com"

Deprecating Powerful Features on Insecure Origins: https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins

Upvotes: 2

Related Questions