I assume that the code you entered calculates the angle between geographic north and the direction to Mecca for the current location. All you have to do is consider the user header.
For example, suppose a user is located in such a way that Mecca directly belongs to the West, and the user collides directly with the East. Since tan returns +/- 90 degrees, the qibla angle should be -90 degrees. The adjustment should now be obvious: you need to subtract 90 degrees from the qibla angle corresponding to the geographic north (-90) in order to reach (-180) degrees, namely, how much the user needs to turn to meet Mecca.
Simply put, you need to โcancelโ the user's rejection, and you do this by subtracting the userโs heading from the qibla corner, which refers to the geographical north.
With the math aside, now you need to observe the course changes and recalculate the qibla angle when changing the title. Finally, make sure you use the trueHeading property.
source share