地理定位html5在网络浏览器上工作,但不在iPhone浏览器上工作

时间:2017-02-27 09:07:18

标签: html ios html5 firefox geolocation

我使用下面的代码来获取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>

1 个答案:

答案 0 :(得分:1)

开启浏览器应用的位置服务。

- 点击“设置”应用程序 -打听个人隐私 - 点击位置服务 - 将开关切换到开启