getCardinalDirection method

String? getCardinalDirection()

Gets a cardinal direction from the heading (if available)

Implementation

String? getCardinalDirection() {
  if (heading == null) return null;

  const directions = ['N', 'NE', 'E', 'SE', 'S', 'SW', 'W', 'NW'];
  final index = ((heading! + 22.5) % 360) ~/ 45;
  return directions[index];
}