bearingBetweenLocations static method

double bearingBetweenLocations(
  1. LatLngInfo latLngFrom,
  2. LatLngInfo latLngTo
)

Implementation

static double bearingBetweenLocations(
    LatLngInfo latLngFrom, LatLngInfo latLngTo) {
  var lat1 = latLngTo.latitude * math.pi / 180;
  var long1 = latLngTo.longitude * math.pi / 180;
  var lat2 = latLngFrom.latitude * math.pi / 180;
  var long2 = latLngFrom.longitude * math.pi / 180;

  var dLon = (long2 - long1);

  var y = math.sin(dLon) * math.cos(lat2);
  var x = math.cos(lat1) * math.sin(lat2) -
      math.sin(lat1) * math.cos(lat2) * math.cos(dLon);

  var brng = math.atan2(y, x);

  brng = (brng.degrees + 360) % 360;

  return brng;
}