// npm i geolib
const { getDistance } = require('geolib');
const distance = getDistance(
{ latitude: 51.5103, longitude: 7.49347 },
{ latitude: 51.5200, longitude: 7.49347 }
)
console.log(distance / 1000) //value in km
//$uj@y
function distance(lat1, lon1, lat2, lon2) {
var p = 0.017453292519943295; // Math.PI / 180
var c = Math.cos;
var a = 0.5 - c((lat2 - lat1) * p)/2 +
c(lat1 * p) * c(lat2 * p) *
(1 - c((lon2 - lon1) * p))/2;
return 12742 * Math.asin(Math.sqrt(a)); // 2 * R; R = 6371 km
}
console.log(distance(51.5103, 7.49347, 51.5200, 7.49347))
//$uj@y
//npm i geopoint
const GeoPoint = require('geopoint');
point1 = new GeoPoint(51.5103, 7.49347);
point2 = new GeoPoint(51.5200, 7.49347);
var distance = point1.distanceTo(point2, true)//output in kilometers
console.log(distance)
//$uj@y