devTool.lua 516 B

1234567891011121314151617
  1. module(..., package.seeall)
  2. PI = 3.14159265359
  3. ERadius = 6371.393
  4. function getDistance( lat1, lng1, lat2, lng2 )
  5. -- body
  6. local radLat1 = lat1 * (PI / 180)
  7. local radLat2 = lat2 * (PI / 180)
  8. local a = radLat1 - radLat2
  9. local b = (lng1 * (PI / 180)) - (lng2 * (PI / 180))
  10. 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)))
  11. local s = s * ERadius
  12. local s = math.floor(s * 10000+0.5) / 10000
  13. return s
  14. end