More information about the Underscore mailing list

[_] Calculating magnetic declination

Jeremy Prior jez at
Fri Aug 16 13:13:11 BST 2013

On Fri 16 Aug 2013, at 12:30:51, "Martin Moore" <martinm at> wrote:

> Today's Friday Afternoon teaser :
> I need to calculate magnetic declination (difference between true and
> magnetic North) for any lon/lat.
> There are plenty if sites that do it, but I need either the algorithm or a
> URL that provides some form of interface for this so I can include in my own
> stuff.

Interesting problem.  It's been a while since I looked at this, so a quick refresher on Wikipedia helped:

Basically, the declination not only varies by latitude and longitude, but also varies over time (and the rates aren't constant!).

Depending on the amount of accuracy you require (and the volume of queries), the best solution is probably to use the NOAA's calculator at:

It has a CSV output option which is trivial to parse.

Jeremy Prior
jez at