They don’t. There’s typically a compass in phones that provides information useful in determining direction.
https://en.wikipedia.org/wiki/Magnetometer
Mobile phones
Many smartphones contain miniaturized microelectromechanical systems (MEMS) magnetometers which are used to detect magnetic field strength and are used as compasses. The iPhone 3GS has a magnetometer, a magnetoresistive permalloy sensor, the AN-203 produced by Honeywell. In 2009, the price of three-axis magnetometers dipped below US$1 per device and dropped rapidly. The use of a three-axis device means that it is not sensitive to the way it is held in orientation or elevation. Hall effect devices are also popular.
The thing says “video unavailable” for me, but this YouTube video from Associated Press seems to have at least the same frame shown in the thumbnail:
https://www.youtube.com/watch?v=yUE7_rlO2RM&list=RDNSyUE7_rlO2RM&start_radio=1