China completed the construction of more than 1.15 million kilometers of transmission lines with conventional voltage levels spanning its vast territory in 2014. This large and complicated power grid structure relies mainly on manual operation and maintenance of lines. Unmanned aerial vehicles (UAVs) equipped with high-definition digital video cameras and cameras and GPS positioning systems can conduct autonomous patrols along the grid. However, the presence of electromagnetic fields around high-voltage transmission lines can affect the UAV's magnetometer, resulting in a wrong heading and thus unsafe flight. In this paper, the traditional method of UAV heading calculation using a magnetometer was analyzed, and a novel method for calculating UAV heading based on dual antennas was proposed. Experimental data showed that the proposed method improves the anti-magnetic interference characteristics of UAVs and increases UAV security and stability for power inspection applications.