SKHuang
2019-12-16 18:05:14 +08:00
func GetDistance(lat1 float64, lng1 float64, lat2 float64, lng2 float64) float64 {
var (
radLat1 float64
radLat2 float64
a float64
b float64
s float64
)
radLat1 = GetRad(lat1)
radLat2 = GetRad(lat2)
a = radLat1 - radLat2
b = GetRad(lng1) - GetRad(lng2)
s = 2 * earth_padius * math.Asin(math.Sqrt(math.Pow(math.Sin(a/2), 2)+math.Cos(radLat1)*math.Cos(radLat2)*math.Pow(math.Sin(b/2), 2)))
return s
}
func GetRad(d float64) float64 {
return d * math.Pi / 180.0
}