1
0
Fork 0
mirror of https://github.com/Luzifer/repo-template.git synced 2024-11-10 08:30:03 +00:00
repo-template/vendor/github.com/Luzifer/go_helpers/position/haversine.go
Knut Ahlers f14ad8331c
Add blacklist for repos
Signed-off-by: Knut Ahlers <knut@ahlers.me>
2018-02-08 22:39:33 +01:00

21 lines
535 B
Go

package position
import "math"
const (
earthRadius = float64(6371)
)
func Haversine(lonFrom float64, latFrom float64, lonTo float64, latTo float64) (distance float64) {
var deltaLat = (latTo - latFrom) * (math.Pi / 180)
var deltaLon = (lonTo - lonFrom) * (math.Pi / 180)
var a = math.Sin(deltaLat/2)*math.Sin(deltaLat/2) +
math.Cos(latFrom*(math.Pi/180))*math.Cos(latTo*(math.Pi/180))*
math.Sin(deltaLon/2)*math.Sin(deltaLon/2)
var c = 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
distance = earthRadius * c
return
}