我试图在页面加载时自动通过html的地理位置获取协调,但它不起作用。
<body >
<p id="demo">hi</p>
</body>
<script>
$(document).ready(function () {
var x = document.getElementById("demo");
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>
非常感谢任何帮助。