bearing method

double bearing(
  1. LatLng p1,
  2. LatLng p2
)

Returns the great circle bearing (direction) in degrees to the next point (p2)

Find out about the difference between rhumb line and great circle bearing on Wikipedia.

final Distance distance = const Distance();

final LatLng p1 = new LatLng(0.0, 0.0);
final LatLng p2 = new LatLng(-90.0, 0.0);

expect(distance.direction(p1, p2), equals(180));

Implementation

double bearing(final LatLng p1, final LatLng p2) {
  final diffLongitude = p2.longitudeInRad - p1.longitudeInRad;

  final y = math.sin(diffLongitude);
  final x = math.cos(p1.latitudeInRad) * math.tan(p2.latitudeInRad) -
      math.sin(p1.latitudeInRad) * math.cos(diffLongitude);

  return radianToDeg(math.atan2(y, x));
}