2 回答

TA貢獻1850條經驗 獲得超11個贊
轉到 Finder -> Apple -> 系統偏好設置 -> 安全和隱私 -> 隱私,然后將 Safari 添加到白名單。試試看是否可行。
或者
在 Safari 中選擇 Safari > 首選項。單擊“首選項”窗口中的“隱私”圖標。取消選擇“拒絕而不提示”選項。

TA貢獻1796條經驗 獲得超7個贊
我通過處理錯誤解決了我的問題。Safari 和 ios 似乎需要錯誤處理才能工作。
這有效:
<!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>
添加回答
舉報