【发布时间】:2017-02-27 09:07:18
【问题描述】:
我使用下面的代码来获取纬度和经度,在网络浏览器 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 html firefox geolocation