> 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).