我在 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/