A heading determination method and an electronic device. The heading determination method comprises: on the basis of data collected in real time by a
magnetometer mounted on a terminal device within a set duration, obtaining a current
magnetic field strength indicator; if a positioning
signal from a navigation
satellite system currently received by the terminal device does not satisfy an availability condition, determining, from a correspondence representing the relationship between historical headings and historical
magnetic field strength indicators, a historical
magnetic field strength indicator matching the current magnetic
field strength indicator; and determining, as a current heading of the terminal device, the historical heading corresponding to the historical magnetic
field strength indicator matched in the correspondence. In the method, when a GNSS
signal is poor, a heading of a terminal device is determined by means of a correspondence between historical headings and historical magnetic
field strength indicators, without requiring calibration of
magnetometer data, thereby reducing overhead, overcoming the problem of the
magnetometer being susceptible to external interference, and improving the accuracy of heading determination.