SensorTag- Magnetometer to compass
Determine which axis of the device is going to point North. That is your north unit vector. Convert the x, y, and z magnetometer data to a vector. From there, use the dot product. \$cos\theta=\dfrac{A\cdot B}{|A||B|}\$

After you have that angle, there are 4 quadrants to a compass:


N 315-45 degrees
E 45-135 degrees
S 135-225 degrees
W 225-315 degrees


Set up a set of conditional statements for those ranges.