Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function calcDistanceBetweenToPoints (point1, point2) {
- const EARTH_RADIUS = 6371e3; // metres
- const latitude1 = point1.lat * Math.PI / 180;
- const latitude2 = point2.lat * Math.PI / 180;
- const deltaLatitude = (point2.lat - point1.lat) * Math.PI / 180;
- const deltaLongitude = (point2.lon - point1.lon) * Math.PI / 180;
- const angle = Math.sin(deltaLatitude/2) * Math.sin(deltaLatitude/2) +
- Math.cos(latitude1) * Math.cos(latitude2) * Math.sin(deltaLongitude/2) * Math.sin(deltaLongitude/2);
- const theta = 2 * Math.atan2(Math.sqrt(angle), Math.sqrt(1 - angle));
- const distance = EARTH_RADIUS * theta;
- return distance; //in metres
- }
- let result = calcDistanceBetweenToPoints({
- lat: -33.2569755, lon: 151.5492134
- },{
- lat: -33.733914, lon: 150.945014
- })
- console.log(result)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement