Is "area id" a thing?

When I run C_Map.GetBestMapForUnit("player") it gives me an ID representing the UiMapID which can be found on https://wow.tools/dbc/?dbc=uimap.db2. Now, let’s say I’m in Goldshire… my UiMapID is 37 (Elwynn Forest).

Goldshire is found on areatable.db2 (https://wow.tools/dbc/?dbc=areatable.db2&bc=eb9dc13f6f32a1b4992b61d6217dd6ab#search=Goldshire&page=1) with ID = 87.

Is there any API function that would return 87 instead of 37?

https://wow.gamepedia.com/API_C_MapExplorationInfo.GetExploredAreaIDsAtPosition

1 Like

Thanks a lot, Ketho! It really had unstuck me.

Would you allow me a last question? I don’t think I’m using the right vector to get my current position:

local ui_map_id = C_Map.GetBestMapForUnit("player")
local unit_x, unit_y = UnitPosition("player")
local unit_vector = CreateVector2D(unit_x, unit_y)
local result = C_MapExplorationInfo.GetExploredAreaIDsAtPosition(ui_map_id, unit_vector)
print(result)

The result is always nil. Am I missing something?

Much appreciated!

Replace with

local unit_x, unit_y = C_Map.GetPlayerMapPosition(ui_map_id, "player"):GetXY()
2 Likes

Thanks a lot!

You can also skip a step since GetPlayerMapPosition already returns a Vector2D

function GetAreaIDsForPlayer()
	local mapID = C_Map.GetBestMapForUnit("player")
	local pos = C_Map.GetPlayerMapPosition(mapID, "player")
	local areaIDs = C_MapExplorationInfo.GetExploredAreaIDsAtPosition(mapID, pos)
	local areaString = areaIDs and table.concat(areaIDs, ", ") or "none"
	print(format("MapID=%d, Position=%.3f:%.3f, AreaIDs=%s", mapID, pos.x, pos.y, areaString))
end
1 Like

Got it.

But if I understood correctly, GetExploredAreaIDsAtPosition returns the areaIDs that I already explored around my position, which can return more than one location, right?

I’m wondering if I can get my current area ID from the results of this function call.

Take a look at Blizzard’s function MapUtil.FindBestAreaNameAtMouse

https://www.townlong-yak.com/framexml/live/MapUtil.lua#43
function MapUtil.FindBestAreaNameAtMouse(mapID, normalizedCursorX, normalizedCursorY)
	local exploredAreaIDs = C_MapExplorationInfo.GetExploredAreaIDsAtPosition(mapID, CreateVector2D(normalizedCursorX, normalizedCursorY));
	if exploredAreaIDs then
		for i, areaID in ipairs(exploredAreaIDs) do
			local name = C_Map.GetAreaInfo(areaID);
			if name then
				return name;
			end
		end
	end
	return nil;
end
1 Like

From what I understand, it can return more than one location and the first location will be used for GetAreaInfo to show the area name for the mouse location on the worldmap

https://www.townlong-yak.com/framexml/8.1.5/MapUtil.lua#43

I don’t know what exactly you’re trying to do but the first returned area ID could be the closest to your current location. However GetExploredAreaIDsAtPosition doesn’t always seem to return information for every part of the zone. Otherwise you could do some math with map coords or check GetSubZoneText if all you want is the current subzone text

1 Like

I think I can mix both solutions to get what I need for my addon. GetSubZoneText by itself wouldn’t solve because I need the area ID. I can try to compare it with C_Map.GetAreaInfo(areaID) and return the areaID.

Update: Guys, thanks a lot!

It worked perfectly!

I’ve just tweaked FindBestAreaNameAtMouse to return the areaID instead of the name.

I appreciate all the help you gave me today!