bearing method

double bearing(
  1. Coordinate startPoint,
  2. Coordinate endPoint
)

This function is for the initial bearing (sometimes referred to as forward azimuth) which if followed in a straight line along a great-circle arc will take you from the start point to the end point

startPoint Initial coordinates endPoint Final coordinates Returns Bearing in degrees from North, 0° ... 360°

final istCoordinates = Coordinate(41.28111111, 28.75333333); // The coordinates of Istanbul Airport
final jfkCoordinates = Coordinate(40.63980103, -73.77890015); // The coordinates of New York JFK Airport
final greatCircle = GreatCircle();
final bearing = greatCircle.bearing(istCoordinates, jfkCoordinates);

Implementation

double bearing(Coordinate startPoint, Coordinate endPoint) {
  if (startPoint == endPoint) return 0.0;
  final double lat1 = startPoint.latitude.toRadians();
  final double lat2 = endPoint.latitude.toRadians();
  final double lon1 = startPoint.longitude.toRadians();
  final double lon2 = endPoint.longitude.toRadians();
  final double dLon = lon2 - lon1;
  final double y = sin(dLon) * cos(lat2);
  final double x =
      (cos(lat1) * sin(lat2)) - (sin(lat1) * cos(lat2) * cos(dLon));
  final double bearing = atan2(y, x).toDegrees().wrap360();
  return bearing;
}