When I was a kid at some point I just realized I could close my eyes and try to visualize my room that I knew really well. And then I'd imagine what it would look like if I looked at it making a 90 degree right turn. Then visualizing what happens if I walked out of the room, then up the stairs, etc. And then trying to make sure that as I'm doing these turns around corners in my house, connecting it with if I'm facing north/east/south/west until it became second nature to know that. And then as I got older I connected it implicitly with other senses of my surroundings (e.g. time of day + location of sun = you know which direction).
I'd just sit for like 5-10 minutes at a time every day doing that until I got "bored" by the skill. Not necessarily sure if it's something you can practice as I know there's actual brain structural differences that can determine whether you have this skill and how advanced it is, and I'd imagine it's potentially harder to rewire your brain for this as an adult.