calculateBearing static method

double calculateBearing(
  1. LatLng from,
  2. LatLng to
)

Calculate the bearing (direction in degrees) between two points

Implementation

static double calculateBearing(LatLng from, LatLng to) {
  final lat1 = _degToRad(from.latitude);
  final lon1 = _degToRad(from.longitude);
  final lat2 = _degToRad(to.latitude);
  final lon2 = _degToRad(to.longitude);

  final dLon = lon2 - lon1;
  final y = Math.sin(dLon) * Math.cos(lat2);
  final x = Math.cos(lat1) * Math.sin(lat2) -
      Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon);
  return (_radToDeg(Math.atan2(y, x)) + 360) % 360;
}