Ese script no funcionará.
Lo corrijo:
function getNearestMarkerToPosition(x, y)
local minDistance=math.huge
local nearestMarker = nil
for index, marker in ipairs(getElementsByType("marker")) do
local mx, my = getElementPosition(marker)
local distance = getDistanceBetweenPoints2D(x, y, mx, my)
if (distance<minDistance) then
minDistance=distance
nearestMarker = marker
end
end
return nearestMarker
end