Compass.js allow you to get compass heading in JavaScript by PhoneGap, iOS API or GPS hack.