Module:Coordinates: Difference between revisions

Switch to template gadget category per request
 
m 1 revision imported: Content from Template:Location Map on Wikipedia
 
(2 intermediate revisions by 2 users not shown)
Line 691: Line 691:
type = mw.text.trim(type)
type = mw.text.trim(type)
if type == 'lat' or type == 'long' then
if type == 'lat' or type == 'long' then
local result, negative = mw.text.split((mw.ustring.match(coord,'[%.%d]+°[NS] [%.%d]+°[EW]') or ''), ' ')
        local coordString = mw.ustring.match(coord,'[%.%d]+°[NS] [%.%d]+°[EW]')
        if not coordString then
            return nil
        end
local result = mw.text.split(coordString, ' ')
        local negative
if type == 'lat' then
if type == 'lat' then
result, negative = result[1], 'S'
result, negative = result[1], 'S'
Line 697: Line 702:
result, negative = result[2], 'W'
result, negative = result[2], 'W'
end
end
        if not result then
            return nil
        end
result = mw.text.split(result, '°')
result = mw.text.split(result, '°')
        if not result[1] then
            return nil
        end
if result[2] == negative then result[1] = '-'..result[1] end
if result[2] == negative then result[1] = '-'..result[1] end
return result[1]
return result[1]
Line 706: Line 717:


function coordinates.coord2text(frame)
function coordinates.coord2text(frame)
return coordinates._coord2text(frame.args[1],frame.args[2])
return coordinates._coord2text(frame.args[1],frame.args[2]) or ''
end
end