chore: merge backend repo history into monorepo at backend/
git-subtree-dir: backend git-subtree-mainline:dc11190527git-subtree-split:acae976622
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
package utils
|
||||
|
||||
import "math"
|
||||
|
||||
const earthRadiusKM = 6371.0
|
||||
|
||||
// HaversineKM فاصلهی تقریبی بین دو مختصات جغرافیایی رو به کیلومتر برمیگردونه.
|
||||
func HaversineKM(lat1, lng1, lat2, lng2 float64) float64 {
|
||||
toRad := func(deg float64) float64 { return deg * math.Pi / 180 }
|
||||
|
||||
dLat := toRad(lat2 - lat1)
|
||||
dLng := toRad(lng2 - lng1)
|
||||
|
||||
a := math.Sin(dLat/2)*math.Sin(dLat/2) +
|
||||
math.Cos(toRad(lat1))*math.Cos(toRad(lat2))*math.Sin(dLng/2)*math.Sin(dLng/2)
|
||||
c := 2 * math.Atan2(math.Sqrt(a), math.Sqrt(1-a))
|
||||
|
||||
return earthRadiusKM * c
|
||||
}
|
||||
Reference in New Issue
Block a user