I want to code a page where i can click a button it gives the current position then another and get new potion and then tell me how far i have walked. I don't need to calculate the curve the earth or anything i am not walking that far LOL. I also don't want to have it constantly going and updating the geolocation. here is what i have, where did i go wrong? it keeps reading NaN... I am self taught so i may have some knowledge gaps..LOL thx in advance for the help
<html>
<body>
<p>Click the button to get your coordinates.</p>
<button onclick="getLocation()">start</button>
<BR><br><br>
<button onclick="getLocation2()">stop</button>
<button onclick="tods()">total</button>
<BR><br><br>
<p id="demo">something1</p>
<BR>
<p id="demo2">something2</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;
}
var y = document.getElementById("demo2");
function getLocation2() {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition2);
} else {
y.innerHTML = "Geolocation is not supported by this browser.";
}
}
function showPosition2(position2) {
y.innerHTML = "Latitude: " + position2.coords.latitude +
"<br>Longitude: " + position2.coords.longitude;
}
</script>
<script>
function tods() {
var z = x.innerHTML - y.innerHTML;
document.getElementById("total").innerHTML = z;
}
</script>
<p id="total">something 3</p>
</body>
</html>