geodeticHeading method

double geodeticHeading({
  1. required double startLatitude,
  2. required double startLongitude,
  3. required double endLatitude,
  4. required double endLongitude,
})

Calculates the geodetic heading WGS84 to true north represented as 0 and rotating around 360 degrees.

Implementation

double geodeticHeading({
  required double startLatitude,
  required double startLongitude,
  required double endLatitude,
  required double endLongitude,
}) {
  // Get the initial data from our variables:
  final lat1 = startLatitude * (math.pi / 180);
  final lon1 = startLongitude * (math.pi / 180);
  final lat2 = endLatitude * (math.pi / 180);
  final lon2 = endLongitude * (math.pi / 180);

  // Set up our calculations
  final y = math.sin(lon2 - lon1) * math.cos(lat2);
  final x = math.cos(lat1) * math.sin(lat2) -
      math.sin(lat1) * math.cos(lat2) * math.cos(lon2 - lon1);
  var rtnval = math.atan2(y, x) * (180 / math.pi);
  rtnval = (rtnval + 360) % 360;
  return rtnval;
}