Lua 计算两个GPS坐标点之间的距离


local EARTH_RADIUS = 6378.137
local function rad(d)
  return d * math.pi / 180.0
end

local function getDistance(lat1,lng1,lat2,lng2)
  local radLat1 = rad(lat1)
  local radLat2 = rad(lat2)
  local a = radLat1 - radLat2
  local b = rad(lng1) - rad(lng2)
  local s = 2 * math.asin(math.sqrt(math.pow(math.sin(a/2),2) +
  math.cos(radLat1)*math.cos(radLat2)*math.pow(math.sin(b/2),2)))
  s = s * EARTH_RADIUS
  return s*1000 -- 单位米
end

原文地址:https://www.cnblogs.com/xilanglang/p/6697892.html