I am building application where i am getting the user's latitude
and longitude
using the below code
<!DOCTYPE html> <html> <body>
<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>
</body> </html>
Now i want to convert it to kilometre so that i can compare with other latitude and longitude and calculate the difference between them in kilometre.