A method, using patches fixed to a surface of a body, the patches including respective electrodes in contact with the surface, and at least one of the patches configured to output a signal in response to a magnetic field applied to the body. Initially, the signal is processed to compute first magnetic locations and first electrical locations of the at least one of the patches. Subsequently, the signal is processed to compute second magnetic locations and second electrical locations of the at least one of the patches. A first relation is computed between the first magnetic and the first electrical locations, a second relation is computed between the second magnetic and the second electrical locations, and upon detecting a difference between the second and the first relations, a magnetic location correction is computed and then applied to track a position of a magnetic sensor inside the body.