Is there a way to get approximate value of magnetic declination from GPS coordinates?

My Arduino-based device has a Magnetometer and a GPS, and uses magnetic declination in calculations. I would like to avoid having to configure it by hand.

I have found references to https://www.ngdc.noaa.gov/geomag/WMM/soft.shtml online, but the site seems to be down (Google has a cache of the site but not of the code).

Is there another way of getting magnetic declination from GPS coordinates? Doesn't have to be precise, +/- 10% would work just fine.

1 Answer 1


No, the North pointed by GPS coordinates are extracted using the velocity heading which would represent the true North. If you get the ECEF (earth centered earth fixed) coordinates from the GPS you can convert it to a local ENU (east north up frame) and calculate the heading from the velocity vectors (take a look here if you need the formulas for that).

However, this site http://www.magnetic-declination.com/ can provide you a estimate for magnetic declination at your location.

EDIT From the comment I came across this topic which lead to this

you can play with the code provided and take it as a template for your needs to create a lookup table. The software used for creation of the files is the one present in the site you pointed. Just downloaded the linux zip file and tested it with the sample txt coordinates provided and all seems ok.

For the record the command used was (yes for some reason the extension exe is present but this is linux binary):

./wmm_file.exe f sample_coords.txt out.txt

which created a out.txt equal to sample output file provided. Now this file can be used by the function void build_lookup_table() (present on grab60_char.c) to build the lookup table you need.

  • I'm basically only looking for an offline lookup table of data on that site. I already have latitude, longitude and altitude coordinates (either hardware or software does the transformations already).
    – frnhr
    Jun 17, 2016 at 11:40
  • 1
    @frnhr I edit my answer with more info I came across, hope it helps you.
    – brtiberio
    Jun 17, 2016 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.