Having gotten lost a couple times in the woods I can speak to how difficult it can be determining direction in rough terrain and on overcast days. Having a compass is a good idea, but before going into isolated settings you really need to have an understanding of what lies in what direction. If you don’t automatically know that, look at a map beforehand so as to have a basic idea of where you’ll be.
The same principles apply in urban settings. I always look at maps before going someplace new and carry maps in my vehicles.