Last active
October 3, 2023 18:44
-
-
Save manix/7ce097c73728e07178af74cb4c62a341 to your computer and use it in GitHub Desktop.
Distance between points simplified
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
getDistanceFromLatLonInM(lat1, lon1, lat2, lon2) { | |
var deg2rad = deg => deg * 0.017453293; | |
var a = | |
Math.pow(Math.sin(deg2rad(lat2 - lat1) / 2), 2) + | |
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) * | |
Math.pow(Math.sin(deg2rad(lon2 - lon1) / 2), 2); | |
return 12742000 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); | |
} |
Meters, as it says in the name, conforming to Si.
meters is usually lowercased, also line 2 should be 0.017453293, not 0,017453293
meters is usually lowercased, also line 2 should be 0.017453293, not 0,017453293
In the function name it goes as a separate word "Meters" that's why it is a capital letter. Also I have no idea how a comma ended up in the number, I fixed it thanks for the pointer.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
is this in meters or miles?