Created
June 6, 2017 22:31
-
-
Save kuba--/78bebdcb33e558294f6370821b13a551 to your computer and use it in GitHub Desktop.
Haversine formula
This file contains hidden or 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
func dist(lat1, lon1, lat2, lon2 float64) float64 { | |
const R = 1000.0 * 6378.132 // Radius of earth in m. | |
lat := lat2*math.Pi/180.0 - lat1*math.Pi/180.0 | |
lon := lon2*math.Pi/180.0 - lon1*math.Pi/180.0 | |
a := math.Sin(lat/2.0)*math.Sin(lat/2.0) + math.Cos(lat1*math.Pi/180.0)*math.Cos(lat2*math.Pi/180.0)*math.Sin(lon/2.0)*math.Sin(lon/2.0) | |
c := 2.0 * math.Atan2(math.Sqrt(a), math.Sqrt(1.0-a)) | |
d := R * c | |
return d | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment