A method for measuring an ambient magnetic field using a scalar magnetometer which comprises: - an optical pumping source able to emit a laser beam towards a cell filled with a gas along a direction of propagation, - a polarisation rotator able to rotate the direction of polarisation of the laser beam by being driven by a polarisation orientation set point, - a magnetic resonance excitation source, - a photodetector receiving the laser beam that passed through the cell and providing an electric signal, - a first control system configured to make a frequency control of the magnetic resonance excitation source from a first component of the electric signal, the method being characterised in that it includes the steps of: - vectorially measuring the ambient magnetic field, - from said vectorial measurement, calculating: ∘ an alignment deviation ( α B, k) of the ambient magnetic field relative to the direction of propagation of the laser beam, and ∘ a theoretical rotation angle ( θ pol theo) to be supplied to the polarisation of the pump laser beam in a plane orthogonal to the direction of propagation of the laser beam such that the polarisation of the laser beam is orthogonal to the ambient magnetic field, - when the alignment deviation is lower than a threshold, using as the polarisation orientation set point the value of said theoretical rotation angle or the current value of said set point when it has been detected that the alignment deviation is lower than the threshold. - an optical pumping source able to emit a laser beam towards a cell filled with a gas along a direction of propagation, - a polarisation rotator able to rotate the direction of polarisation of the laser beam by being driven by a polarisation orientation set point, - a magnetic resonance excitation source, - a photodetector receiving the laser beam that passed through the cell and providing an electric signal, - a first control system configured to make a frequency control of the magnetic resonance excitation source from a first component of the electric signal, - vectorially measuring the ambient magnetic field, - from said vectorial measurement, calculating: ∘ an alignment deviation ( α B, k) of the ambient magnetic field relative to the direction of propagation of the laser beam, and ∘ a theoretical rotation angle ( θ pol theo) to be supplied to the polarisation of the pump laser beam in a plane orthogonal to the direction of propagation of the laser beam such that the polarisation of the laser beam is orthogonal to the ambient magnetic field, ∘ an alignment deviation ( α B, k) of the ambient magnetic field relative to the direction of propagation of the laser beam, and ∘ a theoretical rotation angle ( θ pol theo) to be supplied to the polarisation of the pump laser beam in a plane orthogonal to the direction of propagation of the laser beam such that the polarisation of the laser beam is orthogonal to the ambient magnetic field, - when the alignment deviation is lower than a threshold, using as the polarisation orientation set point the value of said theoretical rotation angle or the current value of said set point when it has been detected that the alignment deviation is lower than the threshold.