luaプログラムで実行した距離を測定するにはどうすればよいですか?できればGPSロケーションから。経度と緯度の両方があります。
1 に答える
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)
于 2013-02-12T21:47:38.520 に答える