It has nothing to do with gravity. The core of the earth is magnetic and the earth's north pole is actually magnetic north... at least for a while.
Geologists are telling us that the magnetic field is breaking down. There is evidence that the earth has done that a few times in it's history. Some have even claimed that it is actually the cause of global climate change.