I am wondering how compass calibration works / why e.g. drawing an 8 or rotating the phone to all 3 axis works (or at least shall work) - I mean I would understand the calibration process, if an application would say me: Point to north, then press that button down there, but you can start at basically zero knowledge for the app, just by rotating your phone! How is that done? Also, do I need to enter a special calibration mode or can I draw these figures (like the 8) directly in Google Maps? How does Google Maps know that I am not just really moving the phone but want to calibrate the compass? Thanks for any hint!
Compass calibration works by detecting the magnetic field intensity of earth. But sometimes due to strong interference from other electronic devices like transformers, compass sensor may get wrong idea about the magnetic poles of earth and can point in wrong direction.
So to ensure that, it asks users to recalibrate compass by rotating in figure-8 direction so that it can judge the magnetic intensity in all directions. From that data, it deduces the actual poles of earth.
The purpose of calibration is to figure out how to compensate for how the components in your phone (screws, speaker magnets, etc.) interfere with the measured magnetic field.
The calibration process is based on the fact that you can separate the internal and external contributions to the magnetic field by looking at how the field changes as the phone is rotated. For example, in one orientation the magnetic field from the magnet in the speaker will add on to the Earth's field; but when the phone is oriented in the opposite direction, the two fields will partially cancel out.
As you wave the phone around, the magnetometer records how the magnitude of the measured field changes and uses this to calibrate the x, y, and z magnetic field sensors. See geometrikal's answer to a similar question for more details on this process. Note that this calibration does not let you compensate for the influence of other external objects (e.g., your refrigerator) on the magnetic field.
Regarding the implementation in Google Maps: I believe that Google Maps has no control over the compass calibration because there is no such functionality in the Android API. The magnetometer is probably calibrating itself continuously, and Google Maps is just asking you to rotate your phone so that the magnetometer can collect the data it needs to get an accurate calibration.
In other words, you can calibrate your compass any time the magnetic field sensor is being used just by waving your phone – there is no "calibration mode".
At any point in space, the magnetic field strength and direction is the net effect of all the magnetic field sources affecting that point. The earth's magnetic field is one of them. Magnetized screwdrivers, cars, refrigerator magnets, etc. all produce fields. Fields are also produced by current flowing through wires. It's like pouring water into a glass from multiple sources. Once it's in the glass, you can't tell where it came from.
There is no instrument that can determine the "actual poles" of the earth by measuring the magnetic field at a point. What the phone can do, however, is sense the point where the phone axis is parallel to the N/S magnetic force line and determine which end of the phone is north-pointing. If you do your dance far away from objects that might be magnetized, like cars and steel fences, the field the phone is measuring may be primarily the earth's field and hence the phone compass will be properly calibrated. If you then put the phone into a magnetized car, however, it will point the wrong direction for north. The steel in every car is magnetized to one degree or another.
High-precision compasses such are used on aircraft and serious maritime vessels actually have tiny correction magnets that are adjustable with screws for N/S and E/W errors. They are calibrated after installation by turning the vehicle onto known headings (a compass rose painted by a surveyor on a taxiway far from metal buildings, for example) and fussing with the magnets until the compass error is minimized. Then the residual errors are recorded on a "compass correction card" for use in correcting the indicated readings. Search "compass correction card" to see the images.
In theory, the GPS could be used to calibrate the compass when walking or driving since the instantaneous GPS track is accurate. I have not heard of this being done, though it possibly is common. It would work even in a magnetized car. However, in an airplane or a ship, this wouldn't work because the vehicle's heading is to one degree or another usually crabbed slightly into the wind and the GPS has no knowledge of this.