mirror of
https://github.com/commons-app/apps-android-commons.git
synced 2025-10-28 21:33:53 +01:00
* Resolves issue #2239 by adding an arrow for direction * Removed unnecessary change in styles.xml * spacing * javadoc --------- Co-authored-by: Nicolas Raoul <nicolas.raoul@gmail.com>
This commit is contained in:
parent
e99ff1c044
commit
e5c789e874
6 changed files with 105 additions and 5 deletions
|
|
@ -123,4 +123,23 @@ public class LengthUtils {
|
|||
double sinHalf = Math.sin(x * 0.5D);
|
||||
return sinHalf * sinHalf;
|
||||
}
|
||||
|
||||
/**
|
||||
* Computes bearing between the two given points
|
||||
*
|
||||
* @see <a href="https://www.movable-type.co.uk/scripts/latlong.html">Bearing</a>
|
||||
* @param point1 Coordinates of first point
|
||||
* @param point2 Coordinates of second point
|
||||
* @return Bearing between the two end points in degrees
|
||||
* @throws NullPointerException if one or both the points are null
|
||||
*/
|
||||
public static double computeBearing(@NonNull LatLng point1, @NonNull LatLng point2) {
|
||||
double diffLongitute = Math.toRadians(point2.getLongitude() - point1.getLongitude());
|
||||
double lat1 = Math.toRadians(point1.getLatitude());
|
||||
double lat2 = Math.toRadians(point2.getLatitude());
|
||||
double y = Math.sin(diffLongitute) * Math.cos(lat2);
|
||||
double x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(diffLongitute);
|
||||
double bearing = Math.atan2(y, x);
|
||||
return (Math.toDegrees(bearing) + 360) % 360;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue