Well this is stupid simple and I didn't really test it, but I half way copy pasted the code I'm currently using for my minimap coordinates on the BfA beta.
Didn't want to necro any threads, just thought it might be nice for people to have as a reference or something to play around with while trying to make sense of the beta API changes.
Just remember I drycoded it in 2 minutes. Here there might be bugs! And dragons!
Lua Code:
local coords = CreateFrame("Frame", nil, Minimap)
coords:SetFrameLevel(Minimap:GetFrameLevel() + 5)
coords:SetAllPoints()
coords.elapsed = 0
coords.msg = coords:CreateFontString()
coords.msg:SetDrawLayer("OVERLAY")
coords.msg:SetFontObject(GameFontNormal)
coords.msg:SetPoint("BOTTOM", 0, 20)
coords.onUpdate = function(self, elapsed)
self.elapsed = self.elapsed + elapsed
if self.elapsed < .1 then
return
end
local x, y
local mapID = C_Map.GetBestMapForUnit("player")
if mapID then
-- you don't get coordinates in instances
local mapPosObject = C_Map.GetPlayerMapPosition(mapID, "player")
if mapPosObject then
x, y = mapPosObject:GetXY()
end
end
-- just to avoid checking for nil entries and stuff
x = x or 0
y = y or 0
-- hide it when there aren't any coordinates
self.msg:SetShown(x + y > 0)
self.msg:SetFormattedText("%.1f %.1f", x*100, y*100)
self.elapsed = 0
end
coords:SetScript("OnEvent", function(self)
self:SetScript("OnUpdate", self.onUpdate)
end)
coords:RegisterEvent("PLAYER_ENTERING_WORLD")