public final double getBearingDegrees ( Position position ) { double lat1 = toRadians ( lat ) ; double lat2 = toRadians ( position . lat ) ; double lon1 = toRadians ( lon ) ; double lon2 = toRadians ( position . lon ) ; double dLon = lon2 - lon1 ; double sinDLon = sin ( dLon ) ; double cosLat2 = cos ( lat2 ) ; double y = sinDLon * cosLat2 ; double x = cos ( lat1 ) * sin ( lat2 ) - sin ( lat1 ) * cosLat2 * cos ( dLon ) ; double course = FastMath . toDegrees ( atan2 ( y , x ) ) ; if ( course < 0 ) course += 360 ; return course ; }
Returns a great circle bearing in degrees in the range 0 to 360 .