public double getBearing ( LatLong end ) { if ( this . equals ( end ) ) { return 0 ; } double lat1 = latToRadians ( ) ; double lon1 = longToRadians ( ) ; double lat2 = end . latToRadians ( ) ; double lon2 = end . longToRadians ( ) ; double angle = - Math . atan2 ( Math . sin ( lon1 - lon2 ) * Math . cos ( lat2 ) , Math . cos ( lat1 ) * Math . sin ( lat2 ) - Math . sin ( lat1 ) * Math . cos ( lat2 ) * Math . cos ( lon1 - lon2 ) ) ; if ( angle < 0.0 ) { angle += Math . PI * 2.0 ; } if ( angle > Math . PI ) { angle -= Math . PI * 2.0 ; } return Math . toDegrees ( angle ) ; }
Calculates the bearing in degrees of the end LatLong point from this LatLong point .