Take a look at this :
http://bildr.org/2012/02/hmc5883l_arduino/
http://forums.parallax.com/showthread.php/152502-Tilt-Compensation-Magnetometer-(-HMC5883L)
http://www.timzaman.com/?p=1010
http://www.electrodragon.com/w/index.php?title=HMC5883L_Three-Axis_Compass_Magneticfield_Module