我正在开发一个使用地理位置坐标的应用程序。 我使用 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
这样它是永久的,你不需要每次都打开 chrome 浏览器
google-chrome --args --unsafely-treat-insecure-origin-as-secure="http://whatever.test"
如上回答。
关于html - 没有 SSL 连接的地理定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39366758/