The "compass" in your phone is not a real compass because, obviously, it doesn't have a rotating magnetic needle which is always ready to work. Instead, your phone use a magnetometer, a type of sensor who works by analyzing the variations of the magnetic field. That's why you have to make the 8 loop move, to allow the sensor to measure the magnetic field in a 720 degrees space. Sometimes, the environmental interferences are too big and the sensor loose this calibration, and the factors could be anything: metal frame of your building, your car, local magnetic anomalies and so on. Bottomline: you have to deal with it.