作者:中孝雪瑶诗涵 | 来源:互联网 | 2023-09-17 08:51
localEARTH_RADIUS6378.137localfunctionrad(d)returnd*math.pi180.0endlocalfunctiongetDistanc
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