This worked for me!
I don't know how I haven't seen this post before.
I've had the same problem for a year or two with an iPhone 7.
The distance would count down as I approached the cache but the arrow would point in a completely different direction. My problem seemed to be with the Geocaching app not the phone, as the compass worked fine with other apps such as Adventure Lab or Wherigo.
I've tried other fixes suggested on this and other posts but nothing worked until now.
Lifting the top of the phone by about 30 degrees readjusts the arrow to the correct position after a second or two. I might have to do this more than once while navigating to a cache but it's been working for a few days so hopefully this simple action is all it needs.