[Mobile] How to check if user moved left or right?

I’m trying to figure out if there is anyway to tell if the mobile moved to the left or to the right (imagine taking a step left or right).

I imagine this can be split into 2 questions:

  1. Did the phone move “enough”? Should be doable using the accelerometer
  2. Did it move left or right? I guess there are multiple ways of doing this, I was thinking a combination of compass and some initial calibration (ask the user to take a step left or right for calibration).

Is there already something like this out of the box provided by anyone? Tried google but didn’t find anything alike.
If not, am I thinking the workflow correctly, or is there a better way to do it? (I don’t really have Android / phones experience)