Content deleted Content added
that allows getCoords to be much simpler |
decimalToDMS function to reduce duplicated code |
||
Line 105:
if x == math.floor(x) then x = math.floor(x) end
return x
-------------------------------------------------------------------------------
-- decimalToDMS takes a decimal degrees (x) with precision (p)
-- and returns degrees/minutes/seconds according to the precision
local function decimalToDMS(x, p)
if p > 0.5 then -- precision is > 1/2 a degree
if p > 0.008 then -- precision is > 1/2 a minute
s = 0
elseif p > 0.00014 then -- precision is > 1/2 a second
elseif p > 0.000014 then -- precision is > 1/20 second
elseif p > 0.0000014 then -- precision is > 1/200 second
return d, m, s
end
Line 555 ⟶ 583:
elseif datatype == "globe-coordinate" then
-- 'display' parameter defaults to "inline, title" *** unused for now ***
-- local disp = args.display or ""
-- if disp == "" then disp = "inline, title" end
-- format parameter switches from deg/min/sec to decimal degrees
-- default is deg/min/sec -- decimal degrees needs |format = dec
local form = (args.format or ""):lower():sub(1,3)
if form ~= "dec" then form = "dms" end
local lat, long, prec = datavalue.latitude, datavalue.longitude, datavalue.precision
local ns = "N"
local ew = "W"
Line 575 ⟶ 601:
long = - long
end
if form == "dec" then
out[#out+1] = lat .. "°" .. ns .. " " .. long .. "°" .. ew
else
local latdeg, latmin, latsec =
local
▲ if latms > 30 then latdeg = latdeg + 1 end
▲ latms = 0
▲ end
▲ local latmin = math.floor(latms)
▲ local latsec = (latms - latmin) * 60
▲ if latsec > 30 then latmin = latmin +1 end
▲ end
▲ latsec = math.floor(100 * latsec + 0.5) / 100
▲ else -- cap it at 3 dec places for now
▲ latsec = math.floor(1000 * latsec + 0.5) / 1000
▲ end
▲ local longdeg = math.floor(long)
▲ local longms = (long - longdeg) * 60
▲ end
▲ longsec = math.floor(100 * longsec + 0.5) / 100
▲ longsec = math.floor(1000 * longsec + 0.5) / 1000
if latsec == 0 and longsec == 0 then
|