Module:Titled coords explained

-- *** Version 1.1 (Alpha) ***local p =

function p.main(frame) local raw_coords = frame.args[1] local title = frame.args[2] or "" local options = frame.args[3] or ""

local has_seconds = 1 local output = "", coords, sidx, eidx local lat_d, lat_m, lat_s, lat_NS, lon_d, lon_m, lon_s, lon_WE

-- ** Display the raw coordinates obtained from ** if string.find(options,"raw") ~= nil then output = output .. "raw_coords:" .. raw_coords end

-- ** Extract the individual fields from the raw coordinates ** -- ** See https://www.lua.org/manual/5.3/manual.html#6.4.1 ** sidx, _, lat_d, lat_m, lat_s, lat_NS, lon_d, lon_m, lon_s, lon_WE = string.find(raw_coords, "(%d+)/(%d+)/(%d+%.?%d*)/(%a)/(%d+)/(%d+)/(%d+%.?%d*)/(%a)")

if sidx

nil then -- extract without seconds sidx, eidx, lat_d, lat_m, lat_NS, lon_d, lon_m, lon_WE = string.find(raw_coords, "(%d+)/(%d+)/(%a)/(%d+)/(%d+)/(%a)") if sidx

nil then return output .. "
Error: Failed to process raw_coords: " .. raw_coords end if string.find(options,"idx") ~= nil then output = output .. "
start: " .. sidx .. " end: " .. eidx .. " lat_d: " .. lat_d return output end has_seconds = 0 end

if string.find(options,"debug") ~= nil then if has_seconds

1 then output = output .. "
raw_coords:" .. raw_coords .. "
lat dms = " .. lat_d .. "|" .. lat_m .. "|" .. lat_s .. "|" .. lat_NS .. "
lon dms = " .. lon_d .. "|" .. lon_m .. "|" .. lon_s .. "|" .. lon_WE else output = output .. "
raw_coords:" .. raw_coords .. "
lat dm = " .. lat_d .. "|" .. lat_m .. "|" .. lat_NS .. "
lon dms = " .. lon_d .. "|" .. lon_m .. "|" .. lon_WE end end

-- ** URL encode spaces in the title with + ** local enc_title = title:gsub(" ", "+")

-- ** Call passing individual fields and setting the title ** local type_title = "type:mountain&title=" .. enc_title if has_seconds

1 then coords = frame:expandTemplate else coords = frame:expandTemplate -- ** Doesn't like me adding these args ** --"type:mountain","format=dms","name=" .. name}} end

if output ~= "" then return output .. "
" .. coords end

return coordsend

return p

--