Digital Compass on iPad

I have a Wifi only iPad, and I know that it has a 'digital compass'. I know how to access it (click location button in 'Maps' twice). My question is, how does it get it's reading? I know my location is based on my wifi, but what about the compass? Can it sense where my router is or something? If so, how?

It's a digital compass, according to the iPad specs page - in other words, it has a magnetometer the same way the iPhone 3GS and iPad 3G+WiFi does. So it uses a built-in magnetic sensor to read the fields around you... which is why it won't work inside a car or near a strong magnetic field.