2 回答

TA貢獻(xiàn)1780條經(jīng)驗(yàn) 獲得超5個(gè)贊
轉(zhuǎn)到 Finder -> Apple -> 系統(tǒng)偏好設(shè)置 -> 安全和隱私 -> 隱私,然后將 Safari 添加到白名單。嘗試一下是否有效。
或者
在 Safari 中,選擇 Safari > 首選項(xiàng)。單擊“首選項(xiàng)”窗口中的“隱私”圖標(biāo)。取消選擇“拒絕而不提示”選項(xiàng)。

TA貢獻(xiàn)1779條經(jīng)驗(yàn) 獲得超6個(gè)贊
我通過(guò)處理錯(cuò)誤解決了我的問(wèn)題。Safari 和 ios 似乎需要錯(cuò)誤處理才能工作。
這有效:
<!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, showError);
} else {
x.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
x.innerHTML = "Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
function showError(error) {
switch(error.code) {
case error.PERMISSION_DENIED:
x.innerHTML = "User denied the request for Geolocation."
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML = "Location information is unavailable."
break;
case error.TIMEOUT:
x.innerHTML = "The request to get user location timed out."
break;
case error.UNKNOWN_ERROR:
x.innerHTML = "An unknown error occurred."
break;
}
}
</script>
</body>
</html>
- 2 回答
- 0 關(guān)注
- 163 瀏覽
添加回答
舉報(bào)