我正在尝试将在W3Schools上找到的这个函数的经度和纬度设置为一个变量(我们只是说y
and z
),然后我需要显示y
:
<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>
例如,如果我的经度 ( y
) 是 10,纬度 ( z
) 是 15,那么它会显示
y=10
z=15