getCompassValues function
calculating compass Model
Implementation
getCompassValues(
double heading, double latitude, double longitude, String source) {
double direction = heading;
direction = direction < 0 ? (360 + direction) : direction;
double diff = direction - preValue;
if (diff.abs() > 180) {
if (preValue > direction) {
diff = 360 - (direction - preValue).abs();
} else {
diff = (360 - (preValue - direction).abs()).toDouble();
diff = diff * -1;
}
}
turns += (diff / 360);
preValue = direction;
return CompassModel(
turns: -1 * turns,
angle: heading,
qiblahOffset: getQiblaDirection(latitude, longitude, heading),
source: source);
}