Last active
November 20, 2021 16:05
-
-
Save josfaber/f68721f51711c65c9610b2fd1d3ccaa6 to your computer and use it in GitHub Desktop.
Geocoordinates lat long distance
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
/** | |
* returns the distance between two lat long coordinates | |
* (uses degToRad and radToDeg functions below) | |
*/ | |
function latlongdist(lat1, long1, lat2, long2) { | |
var theta = long1 - long2; | |
var miles = (Math.sin(degToRad(lat1)) * Math.sin(degToRad(lat2))) + (Math.cos(degToRad(lat1)) * Math.cos(degToRad(lat2)) * Math.cos(degToRad(theta))); | |
miles = radToDeg(Math.acos(miles)) * 60 * 1.1515; | |
var feet = miles * 5280; | |
var yards = feet / 3; | |
var km = miles * 1.609344; | |
var meters = km * 1000; | |
return { | |
'miles':miles, | |
'feet':feet, | |
'yards':yards, | |
'km':km, | |
'meters':meters | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment