1

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?

mshwf
  • 7,009
  • 12
  • 59
  • 133
  • Are you running the page through a local server environment? It's working fine for me. – APAD1 May 24 '16 at 14:57
  • I run the HTML file on Google chrome, and doesn't work – mshwf May 24 '16 at 14:59
  • Ya, you can't do that. You need to run it through a local server environment such as MAMP. Read here: http://stackoverflow.com/a/5431823/2827407 – APAD1 May 24 '16 at 14:59
  • Possible duplicate of [HTML 5 Geo Location Prompt in Chrome](http://stackoverflow.com/questions/5423938/html-5-geo-location-prompt-in-chrome) – APAD1 May 24 '16 at 15:06

1 Answers1

2

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

Manuel
  • 337
  • 2
  • 6