> I tried to put my phone in the pocket, but then heading fluctuates with every step.
As you're the developer (and a blind user eating your own dog food) I might suggest (for those that want to put their phone in their pocket) looking at using a running filter to smooth the headings and remove the swing of every step.
Savitzky–Golay filters are particularly good for this and (pages of complicated math aside) are really as simple to implement as a straight running average (as you multiply a string of heading values with normalised weights and sum to get the "better heading" .. add a new heading to front of string, drop off the oldest heading from the back, repeat).
It gets into a lot more code, but integrating the accelerometer readings to figure out where in the step you are, and correct the magnetometer readings, could work. It would have to relearn any time the phone shifted in your pocket, but that could become a continuous process while walking.
Probably easier to just put the phone in a hat, though.
As you're the developer (and a blind user eating your own dog food) I might suggest (for those that want to put their phone in their pocket) looking at using a running filter to smooth the headings and remove the swing of every step.
Savitzky–Golay filters are particularly good for this and (pages of complicated math aside) are really as simple to implement as a straight running average (as you multiply a string of heading values with normalised weights and sum to get the "better heading" .. add a new heading to front of string, drop off the oldest heading from the back, repeat).