0
我想在我的網站上填寫表單時獲取用戶的經度和緯度..當我從w3school使用此代碼時,我的網站不顯示任何結果,因爲可能是服務器防止...你能幫我找另一種方法嗎?如何通過隱藏表單輸入獲取用戶的經緯度
<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>