I am trying to make a compass app. But it has a problem when azimuth change from 179 degree to -179 degree and vice versa, compass image moving around 360 degree to come at -179 degree from 179 degree.
I tried to detect significant angle change and then adjust azimuth angle but failed
float angleDifference = Math.abs(azimuthInDegree-currentDeegre);
if (angleDifference>300f) {
if (azimuthInDegree > currentDeegre) {
azimuthInDegree = 360f - azimuthInDegree;
}
if (azimuthInDegree < currentDeegre) {
azimuthInDegree = -azimuthInDegree-360f;
}
}
Done after some experiments