Try this.
Code: Select all
robR_36witC="font:arimo_bold.ttf; size:36px; color: white; halign:left; valign:center;"
lat1=0
lon1=0
background = canvas_add(0, 0, 600, 600, function()
_rect(0,0,400,512)
_fill("blue")
end)
---What this function is doing is creating a TABLE named <waypoints>
local function data_callback(waypoints)
if waypoints ~= nil then
canvas_draw( background,function()
_rect(0,0,400,512)
_fill("blue")
for i=1, #waypoints do
print(" name:" .. waypoints[i]["ICAO"] .. " lon:" .. waypoints[i]["LONGITUDE"] .. " lat:" .. waypoints[i]["LATITUDE"])
_txt(waypoints[i]["ICAO"],robR_36witC,200,100+ (i*35))
end
end)
end
end
function xpl_dataref_subscribe_trottle(...)
-- Local variables
local args = {...}
local user_callback = args[#args - 1]
local delta_ms = table.remove(args, #args)
local data = nil
-- Replace the user callback with our own
args[#args] = function (...)
data = {...}
end
-- Do the actual subscribe
xpl_dataref_subscribe(table.unpack(args))
-- Start a timer that will fire the callback on requested interval
timer_start(0, delta_ms, function()
if data ~= nil then
user_callback(table.unpack(data))
data = nil
end
end)
end
function new_xpl_data(latitude, longitude)
lat1=latitude
lon1=longitude
print("Latitude: " .. lat1)
print("Longitude: " .. lon1)
nav_get_nearest("WAYPOINT",lat1, lon1, 1, data_callback)
data_callback()
end
xpl_dataref_subscribe_trottle("sim/flightmodel/position/latitude", "DOUBLE",
"sim/flightmodel/position/longitude", "DOUBLE", new_xpl_data, 1000)
Keith