Resolves #2239 by adding a compass arrow for direction of nearest item (#5433)

* 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:
Shashwat Kedia 2024-01-15 10:27:44 +05:30 committed by GitHub
parent e99ff1c044
commit e5c789e874
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 105 additions and 5 deletions

View file

@ -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;
}
}