致力于 html5 地理定位。
在 mozilla、chrome、IE 上试过。在它们上工作正常但不适用于 safari。在 mac 上的 safari(8.0.5)、windows 上的 safari(5.1) 上测试
只需点击 url
http://www.w3schools.com/html/html5_geolocation.asp
或
http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_geolocation
<!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>
它提供允许/禁止弹出窗口,但在允许后什么也不做。 我已经在通过 wi-fi 连接的 Mac 上测试了 safari,但也没有在 wi-fi 和 LAN 上测试笔记本电脑。
最佳答案
您连接的是 Wi-Fi 还是有线网络?
当你没有连接到 wi-fi 时,safari 似乎有问题。
来源
关于javascript - html5 地理定位不适用于 safari 浏览器,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32948143/