【问题标题】:How can I enable geolocation in Google chrome?如何在谷歌浏览器中启用地理定位?
【发布时间】:2016-09-21 21:00:13
【问题描述】:

我刚刚发现谷歌浏览器不推荐使用 getCurrentPosition(),因为它们的来源不安全,它们只是允许 HTTPS。但我正在尝试在我的机器上运行这个 html 文件,据我所知,它应该是安全的。

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

但这并没有显示我当前的位置,如果这意味着 chrome 将我的本地机器视为不安全的来源,有没有办法改变它?

【问题讨论】:

标签: javascript html google-chrome


【解决方案1】:

是的,有。根据文档,您可以使用命令行标志启动浏览器或使用 https 进行连接。

命令行标志用于调试和测试目的,https连接用于生产用途:

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

弃用不安全来源的强大功能:https://sites.google.com/a/chromium.org/dev/Home/chromium-security/deprecating-powerful-features-on-insecure-origins

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-26
    • 2013-09-28
    • 2014-09-14
    • 1970-01-01
    • 1970-01-01
    • 2011-01-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多