我使用下面的代码来获取纬度和经度,在网络浏览器 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>
最佳答案
为浏览器应用打开定位服务。
-点击“设置”应用程序 -打听个人隐私 -点击位置服务 - 将开关切换至“开”
关于ios - 地理位置 html5 在网络浏览器上工作,但在 iphone 浏览器上不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42481629/