getCompassValues function

dynamic getCompassValues(
  1. double heading,
  2. double latitude,
  3. double longitude,
  4. String source,
)

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);
}