2013-02-12 45 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