我使用下面的代码来获取lat和long,在网络浏览器chrome,firefox我能够获得位置但是当我在IOS safari和firefox上运行该网站时我无法获取纬度和经度
<!DOCTYPE html>
<html>
<body>
<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>
答案 0 :(得分:1)
开启浏览器应用的位置服务。
- 点击“设置”应用程序 -打听个人隐私 - 点击位置服务 - 将开关切换到开启