2013-02-12 40 views
-1

我该如何测量我与lua程序运行的距离?最好从gps位置。我有经度和纬度。测量我与lua的距离有多远

+0

在什么情况下?在智能手机上?我很乐意帮助你,但添加一些细节,你的问题太模糊。 – Netfangled 2013-02-12 20:52:35

+0

是的,它是智能手机上的应用程序,我使用conora sdk – user1741900 2013-02-12 21:00:19

+0

如果我理解正确,它就像一个计步器,但不是测量步骤,它测量距离?我的第一本能是使用毕达哥拉斯定理。如果您需要总距离运行,而不是从点A到点B的距离,则每X毫秒执行一次。 – Netfangled 2013-02-12 21:04:49

回答

0

我会用一个封闭随着勾股定理这样做:

function odometer(curx, cury) 
    local x = curx or 0 
    local y = cury or 0 
    local total = 0 
    return function(newx, newy) 
     local difx = math.abs(newx - x) 
     local dify = math.abs(newy - y) 
     total = total + math.sqrt(difx * difx + dify * dify) 
     x, y = newx, newy 
     return total 
    end 
end 

在你applicationsd的启动,你会打电话odometer和当前的经度和纬度通过(或者它会默认为0):

myodometer = odometer(longitude, latitude) 

之后,您可以设置您的应用程序调用myodometer每一个,说1000毫秒,同时通过在新的经度和纬度:

myodometer(newlongitude, newlatitude) 

Here's a link to Lua closures

+0

经度差分和纬度差异不等于毕达哥拉斯定理所要求的差分和差分。必须使用更复杂的[公式](http://en.wikipedia.org/wiki/Great-circle_distance)。 – 2013-02-13 06:51:37