How does my phone tell me my elevation even though I'm nowhere near a cell tower? I have the compass app (Comes with the phone) on my iPhone 6 and it can still tell me my elevation even though I have no service, why is this? Is there a magnet or something similar in the phone?

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.