javascript - 地理位置不适用于 chrome

标签 javascript html google-chrome

我在 mozilla 和 chrome 浏览器中使用了以下脚本。在 mozilla 中,它询问我们是否共享位置。但是在 chrome 中它没有显示任何东西。

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

最佳答案

您使用 Chrome50 吗? 他们删除了对非 https 站点的 GeoLocation 支持。

https://developers.google.com/web/updates/2016/04/geolocation-on-secure-contexts-only

关于javascript - 地理位置不适用于 chrome,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37109965/

相关文章:

javascript - 如何使用 jQuery 或 Javascript 获取类名

html - 居中、盒装数学方程

google-chrome - 在Google Chrome中运行无边框或工具栏的独立网络应用

如果图像保存在缓存中,jQuery .load 不会触发(仅限 Chrome)

javascript - CSS 动画导致 z-index 问题

javascript - Ajax 实时搜索不适用于触摸屏手机

javascript - 根据选择选项更改表格单元格内容?

javascript - knockout js : data-bind click not working

javascript - 当我在我的网页上提交表单时,URL 会立即更新其内容

javascript - 每次单击链接时都会执行 .js 文件