附近小店
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

17 lines
400 B

  1. package utils
  2. import "math"
  3. //返回单位为:千米
  4. func GetDistance(lat1, lat2, lng1, lng2 float64) float64 {
  5. radius := 6371000.0 //6378137.0
  6. rad := math.Pi / 180.0
  7. lat1 = lat1 * rad
  8. lng1 = lng1 * rad
  9. lat2 = lat2 * rad
  10. lng2 = lng2 * rad
  11. theta := lng2 - lng1
  12. dist := math.Acos(math.Sin(lat1)*math.Sin(lat2) + math.Cos(lat1)*math.Cos(lat2)*math.Cos(theta))
  13. return dist * radius / 1000
  14. }