Module:Coordinates
From PS:1 Wiki Dev
Jump to navigationJump to search
Documentation for this module may be created at Module:Coordinates/doc
Script error: Lua error: Internal error: The interpreter exited with status 127.
local p = {}
function p.coord(frame)
local args = frame:getParent().args
local lat = tonumber(args[1])
local lon = tonumber(args[2])
local display = args.display or args[3] or 'inline'
local name = args.name or ''
if not lat or not lon then
return '<span class="error">Error: Invalid coordinates</span>'
end
-- Format coordinates for display
local function formatCoord(value, isLat)
local direction
if isLat then
direction = value >= 0 and "N" or "S"
else
direction = value >= 0 and "E" or "W"
end
value = math.abs(value)
local degrees = math.floor(value)
local minutes = (value - degrees) * 60
return string.format("%d°%.4f′%s", degrees, minutes, direction)
end
local latStr = formatCoord(lat, true)
local lonStr = formatCoord(lon, false)
local displayText = latStr .. " " .. lonStr
-- Create map links
local googleMaps = string.format("https://www.google.com/maps?q=%f,%f", lat, lon)
local osmLink = string.format("https://www.openstreetmap.org/?mlat=%f&mlon=%f&zoom=15", lat, lon)
-- Build output
local output = '<span class="geo">'
output = output .. '<span class="plainlinks">'
output = output .. '[' .. googleMaps .. ' ' .. displayText .. ']'
output = output .. '</span>'
output = output .. '</span>'
-- Add microformat data
output = output .. '<span style="display:none">'
output = output .. '<span class="geo-dec" title="' .. lat .. '; ' .. lon .. '">' .. lat .. '; ' .. lon .. '</span>'
output = output .. '</span>'
-- Handle display parameter
if display == 'title' or display == 'inline,title' then
-- Add to page title (coordinates appear at top right)
output = '<span id="coordinates">' .. output .. '</span>'
end
return output
end
return p