It updates when I touch the screen so I know it's connecting to something somehow. Also, roaming is off and I am nowhere near a cell tower when that was taken.
This is determined by satellites in the horizon mapping out where your phone is (according to multiple posts on Stack Overflow, including https://stackoverflow.com/questions/13329714/how-does-my-iphone-get-its-altitude). Note that the accuracy from this method is not usually precise, but it is a rough estimate of your elevation.
It is using GPS signal, from satellites, and possibly air pressure (on iphone 6 and later I believe) for altitude.
And for direction it has a compass, i.e. a sensor which measures the earth's magnetic field.