computeHeading static method

num computeHeading(
  1. ILatLng from,
  2. ILatLng to
)

Implementation

static num computeHeading(ILatLng from, ILatLng to) {
  final fromLat = MathUtil.toRadians(from.latitude);
  final fromLng = MathUtil.toRadians(from.longitude);
  final toLat = MathUtil.toRadians(to.latitude);
  final toLng = MathUtil.toRadians(to.longitude);
  final dLng = toLng - fromLng;
  var x = math.sin(dLng) * math.cos(toLat);
  var y = math.cos(fromLat) * math.sin(toLat) - math.sin(fromLat) * math.cos(toLat) * math.cos(dLng);
  final heading = math.atan2(x, y);

  return (heading.degrees + 360) % 360;
}