Update 1, Aug 2023
Well it's no fun admitting you are wrong, but coming back to my original answer several years later, i'm gonna have to do exactly that.
I originally said that the True North is unaffected by location and that the Magnetic North is. Well, not exactly. The Magnetic North itself is moving, always. And that is why the offset (Declination) between it and the True north also changes, from place to place and over time (see the wiki page and maps).
I also said to add or subtract it depending on your location. Again, slightly wrong: get your declination, which will vary in different locations, and then add it (to Magnetic North) if it is a "West (negative) Declination" or subtract it if it is a "East (positive) Declination".
That's not computer science, that's geography. But we ARE in computer science, and we need to consider possible values of the function GetDeclination(): They may be either negative or positive, and because of that, the equation TrueNorth = MagneticNorth - GetDeclination()
is the correct form to use, and not MagneticNorth + GetDeclination()
. I'm not sure why I got the equation wrong in my original post. I did say the on positive decilination, the Magnetic North is to the east of the TrueNorth, so why would i suggest adding the declination..?
Examples:
- Ng = 40, GetDec() = 10, Nt = 30; With positive declincation the NorthTrue is indeed to the west of NorthMagnetic.
- Ng = 40, GetDec() = -5, Nt = 45; With negative declination is indeed to the east of NorthMagnetic.
Original Answer
I got here because I was asking the same question myself. I am researching this at this very moment, so I may be slightly mistaken.
You want the TRUE north, the one that is unaffected by your location (to be more exact, you location is affected by the magnetic fields of earth, link).
When navigating, you are supposed to ADD or SUBTRACT declination, depending (I think) on your location when you use the compass, that is, is the magnetic north east or west to the true north? east\west declination.
The class "GeomagneticField" can calculation that offset for you, and if I understand the method's description correctly, it also tells you wether you have east or west declination: positive is how much east you are, negative for how much west you are.
- Get your heading, that is you relative to magnetic north (obtained by magnetic sensor)
- Get your declination
if declination is positive, your magnetic north is east to the true north, so your heading is "to the right" by (some degrees) from the true north! we ADD, hence: heading (magnetic) + declination = true north
if declination is negative, your magnetic north is west to the true north, so your heading is "to the left" by (some degrees) from the true north! we SUBTRACT (the absolute value!), hence: heading (magnetic) - declination = true north.
nice! we can actually see that subtracting absolute value is just like adding the negative degrees, so i guess you can always just add the declination to your heading.
So that's that for you, the why and the what (bottom line i'd say add). Like I said, i just cross-referenced a few pages to get that answer (the above mentioned and also this one, so please double check my links and verify my answer :)