bearing method
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.
Distance distance = Distance();
LatLng position = new LatLng(0.0, 0.0); LatLng destination = new LatLng(-90.0, 0.0);
expect(distance.bearing(position, destination), equals(180));
Implementation
double bearing(dynamic position, dynamic destination) {
position = LatLng.from(position);
destination = LatLng.from(destination);
final longDiff = destination.longitudeInRad - position.longitudeInRad;
final y = math.sin(longDiff);
final x = (math.cos(position.latitudeInRad) *
math.tan(destination.latitudeInRad)) -
(math.sin(position.latitudeInRad) * math.cos(longDiff));
return radianToDeg(math.atan2(y, x));
}