bearingBetween method

double bearingBetween(
  1. double startLatitude,
  2. double startLongitude,
  3. double endLatitude,
  4. double endLongitude,
)

Initial bearing (forward azimuth) from start to end coordinates, expressed in degrees.

Implementation

double bearingBetween(
  double startLatitude,
  double startLongitude,
  double endLatitude,
  double endLongitude,
) {
  final startLat = _radians(startLatitude);
  final startLon = _radians(startLongitude);
  final endLat = _radians(endLatitude);
  final endLon = _radians(endLongitude);

  final y = math.sin(endLon - startLon) * math.cos(endLat);
  final x =
      math.cos(startLat) * math.sin(endLat) -
      math.sin(startLat) * math.cos(endLat) * math.cos(endLon - startLon);
  return _degrees(math.atan2(y, x));
}