Magnetic Variation
Use the magnetic variation (more properly, the "magnetic declination") API to find the offset of magnetic north from true north at a given latitude and longitude within the simulator.
In the real world, the Earth's magnetic field is irregular, such that true north (the direction along a meridian toward the north pole) does not necessarily match what a magnetic compass shows as north.
Using this API ensures that you present the same offsets to users as X-Plane's built-in instruments.
XPLMGetMagneticVariation
function
Returns X-Plane's simulated magnetic variation (declination) at the indication latitude and longitude.
XPLM_API float XPLMGetMagneticVariation(
double latitude,
double longitude
);
XPLMDegTrueToDegMagnetic
function
Converts a heading in degrees relative to true north into a value relative to magnetic north at the user's current location.
XPLM_API float XPLMDegTrueToDegMagnetic(
float headingDegreesTrue
);
XPLMDegMagneticToDegTrue
function
Converts a heading in degrees relative to magnetic north at the user's current location into a value relative to true north.
XPLM_API float XPLMDegMagneticToDegTrue(
float headingDegreesMagnetic
);