html - 没有 SSL 连接的地理定位

标签 html geolocation

我正在开发一个使用地理位置坐标的应用程序。 我使用 HTML5 地理定位功能找出网站访问者的位置,但问题出在 Chrome 上,它不支持不安全来源的地理定位。

  function showPosition(){
    if(navigator.geolocation){
        navigator.geolocation.getCurrentPosition(function(position){
            var positionInfo = "Your current position is (" + "Latitude: " + position.coords.latitude + ", " + "Longitude: " + position.coords.longitude + ")";
            document.getElementById("result").innerHTML = positionInfo;
        });
    } else{
        alert("Sorry, your browser does not support HTML5 geolocation.");
    }
}

这里的代码 getCurrentPosition 无法正常工作,因为我的站点未连接 SSL。

Chrome 警告:getCurrentPosition() 和 watchPosition() 不再适用于不安全的来源。要使用此功能,您应该考虑将您的应用程序切换到安全来源,例如 HTTPS。

有没有其他方法可以在 chrome 上获取坐标/LatLong 值? [仅限不安全连接]

编辑:它在我的机器上使用 localhost:80 工作,但在 http 上的测试 url 中不工作

最佳答案

非常简单:打开 Chrome,打开此地址并输入您要为其启用的域

chrome://flags/#unsafely-treat-insecure-origin-as-secure

enter image description here

这样它是永久的,你不需要每次都打开 chrome 浏览器

google-chrome --args --unsafely-treat-insecure-origin-as-secure="http://whatever.test"

如上回答。

关于html - 没有 SSL 连接的地理定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39366758/

相关文章:

javascript - 'Except IE8' 的条件注释 ?

html - CSS:如何使字段集和多选框具有相同的高度?

jQuery 动画高度,为什么我的 div 从左边开始动画?

javascript - 你如何在表单中做一个强制性的复选框?

javascript - 如何从 Google 版本 map 中拖动的标记获取格式化地址

mapping - 如何获得特定地标的纬度和经度?

math - 如何将纬度或经度转换为米?

html - CSS 背景图像淡化为白色

c# - 如何在 c# 中基于 android 中的移动 sim 网络获取用户位置”?

javascript - 错误的结果箭头( Angular )到地理定位