ios - 地理位置 html5 在网络浏览器上工作,但在 iphone 浏览器上不工作

标签 ios html firefox geolocation

我使用下面的代码来获取纬度和经度,在网络浏览器 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/

相关文章:

ios - 替换父 View Controller

ios - 如何使用 SwiftUI 从 noChannelsView 启动并立即打开您的第一个 channel ?

javascript - 未捕获的语法错误 : Unexpected token C in JSON at position 0

jQuery 事件适用于 Firefox,不适用于 Chrome

html - Firefox 中的 Helvetica Neue 字体问题

firefox - 当标题中不存在内容长度时,如何在 Firefox 中加载进度条

ios - 动态 View 渲染,SwiftUI

ios - UIApplication.shared.applicationIconBadgeNumber 滞后

html - 在 bootstrap 3.3.7 中更改导航栏断点

html - 内容重叠侧边栏