I am trying to set the longitude and latitude of this function found on W3Schools to a variable (let's just say y
and z
), then I need to display 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>
For example, if my longitude (y
) is 10 and latitude (z
) is 15, then it displays
y=10
z=15