Get magnetic declination

hello, first of all sorry for my english, i am trying to get the terrestrial magnetic declination, can someone help me?
Thanks in advance

Magnetic declination is different for every latitude/longitude and the declination is constantly changing.

Here is one way to the declination for your location:

see also World Magnetic Model | NCEI

Thank you for your answer :slight_smile: , I know it varies depending on the localistion but some compass application provides the declination so I imagine it is possible to recover it

Yes, use the GMM model for virtually any location on the planet. :astonished: Declination can be calculated mathematically or a Web page can do the calculation for you. Use a GET request at a site like World Magnetic Model Calculator to provide an xml or json file with all the magnetic information. Once you have that file, use dictionaries or List blocks to extract what is needed.

Here we have an extension to calculate the magnetic declination, it is based on...

In the test I get an error of 20'.

1 Like

Well, you learn something new every day :slight_smile:

This video explains it quite nicely (although it doesn't give the calculation)

Thank you all for your help :slight_smile:

thank you Juan, do you know if I can indicate the longitude and latitude myself with this program to check the declination values ​​everywhere on the planet?

how much is the declination for you? for me 0.25 is to check if it works correctly

You can do that with the app mentioned in the link in post #9. There is a link to the aia for the WMMdeclination example app.

I have updated the extension, now the GeomagneticFieldHere event gets the current position information (You have to wait a while for the GPS to do its job).

GeomagneticField block performs the calculation with the supplied data, gets Declination, FieldStrengh, HorizontalStrength, Inclination, X, Y, Z, currentTimeMillis

  • However I keep getting an error, in my position I should get -0.40 but I get -0.71, an error of about 20 minutes.

using the WMM model. :slight_smile: Since Android uses the World Magnetic Model something might be off in your extension math rounding perhaps @Juan_Antonio . or how the algorithm use the date info.

The extension code does not use calculations, it is based on the GeomagneticField class, it supplies data in float and currentTimeMillis, and the class directly returns the calculation.

@SimpleFunction(description = "Return: Declination, FieldStrengh, HorizontalStrength, Inclination, X, Y, Z, currentTimeMillis")	
public String GeomagneticField(String latitude, String longitude, String altitude) {
float latitude_f = Float.parseFloat(latitude);
float longitude_f = Float.parseFloat(longitude);
float altitude_f = Float.parseFloat(altitude);

GeomagneticField geoField = new GeomagneticField(latitude_f, longitude_f,altitude_f, System.currentTimeMillis());

String salida = String.valueOf(geoField.getDeclination()) + "," + String.valueOf(geoField.getFieldStrength()) + "," + String.valueOf(geoField.getHorizontalStrength()) + "," + String.valueOf(geoField.getInclination()) + "," + String.valueOf(geoField.getX()) + "," + String.valueOf(geoField.getY()) + "," + String.valueOf(geoField.getZ() + "," + System.currentTimeMillis());
return salida;

New York: 12.61° W ± 0.37°

With extension: -12.756147, so it's within tolerance ± 0.37°