mirror of
https://github.com/Luzifer/repo-template.git
synced 2024-11-14 02:12:44 +00:00
21 lines
535 B
Go
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
|
|
}
|