Function to calculate distance between two coordinates

I’m currently using the function below and it doesn’t work properly. According to Google Maps, the distance between these coordinates (from 59.3293371,13.4877472 to 59.3225525,13.4619422) are 2.2 kilometres while the function returns 1.6 kilometres. How can I make this function return the correct distance? function getDistanceFromLatLonInKm(lat1, lon1, lat2, lon2) { var R = 6371; // Radius … Read more