You might look into a magnetometer:
https://en.wikipedia.org/wiki/Magnetometer
https://www.adafruit.com/product/1120
Here's link to a video I made about using one to create an HTML5 animated compass:
https://www.youtube.com/watch?v=2YW6HWJg4f4
Here's a link to code I used and some install instructions for the Pi:
http://www.raspberryperl.com/compass/
You might look into a magnetometer:
https://en.wikipedia.org/wiki/Magnetometer
https://www.adafruit.com/product/1120
Here's link to a video I made about using one to create an HTML5 animated compass:
https://www.youtube.com/watch?v=2YW6HWJg4f4
Here's a link to code I used and some install instructions for the Pi:
http://www.raspberryperl.com/compass/