When we put a conductor carrying a current in a magnetic field, the current is subject to the force of the magnetic field, and the current is formed by the directional motion of free electrons, so essentially the electrons are subject to the force of the magnetic field. If we don't let the wire move, then the electrons in it will get crowded on one side of the wire, with an extra negative charge; The other side has a positive charge because it's missing electrons. This creates an electric field on either side of the wire, a phenomenon known as the hall effect.
When the current and magnetic field are fixed, the strength of the "hall effect" is related to the orientation of the conductor in the magnetic field. The larger the Angle between the conductor and the magnetic field, the stronger the hall effect is. It is by using this simple physical principle that sensitive and lightweight magnetic sensors are derived, which can help us find the right direction.
Some people may ask, is it necessary to install an "electronic compass" when mobile phones have GPS positioning function? Actually very necessary!
If you're in a forest or in a big building, your phone is likely to lose its GPS signal, and an "electronic compass" will ensure you don't get lost because the earth's magnetic field is everywhere.
It's also important to note that if we're stationary or moving very slowly, GPS can only tell us where we are, not where we're going. Open the navigation map and you'll see a small dot showing where you are, and an "electronic compass" will show an arrow that rotates with the phone's orientation. Therefore, "electronic compass" is not an optional sensor, but an important supplement to GPS positioning.