Skip to content

Instantly share code, notes, and snippets.

@aaryadev
Created February 28, 2015 06:55
Show Gist options
  • Save aaryadev/3f060bb8e8bf1007e59f to your computer and use it in GitHub Desktop.
Save aaryadev/3f060bb8e8bf1007e59f to your computer and use it in GitHub Desktop.
bearing between 2 gps location
public static double gpsbearing(double lat1, double long1, double lat2, double long2){
double dLon= Math.toRadians(long2-long1);
double latA=Math.toRadians(lat1);
double latB=Math.toRadians(lat2);
double y = Math.sin(dLon) * Math.cos(latB);
double x = Math.cos(latA) * Math.sin(latB) - Math.sin(latA) * Math.cos(latB) * Math.cos(dLon);
double bearing = Math.toDegrees(Math.atan2(y, x));
return bearing;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment