computeHeading static method
Returns the heading from one LatLng to another LatLng. Headings are expressed in degrees clockwise from North within the range [-180,180). @return The heading in degrees clockwise from north.
Implementation
static num computeHeading(LatLng from, LatLng to) {
// http://williams.best.vwh.net/avform.htm#Crs
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;
final heading = atan2(sin(dLng) * cos(toLat),
cos(fromLat) * sin(toLat) - sin(fromLat) * cos(toLat) * cos(dLng));
return MathUtil.wrap(MathUtil.toDegrees(heading), -180, 180);
}