Eric Bergman-Terrell's Blog

Math Tip: How to Determine the Angle Between Two Geographical Locations
October 4, 2010

Use the following method to determine the angle subtended at the earth's center by two geographical coordinates. Latitude is positive north of the equator. Longitude is negative west of Greenwich. Both latitude and longitude are specified in degrees:

public static double AngleBetweenLocations(double Lat1Degrees, 
                                           double Lon1Degrees, 
                                           double Lat2Degrees, 
                                           double Lon2Degrees)
{
  double Lat1Radians = Radians(Lat1Degrees);
  double Lon1Radians = Radians(Lon1Degrees);
  double Lat2Radians = Radians(Lat2Degrees);
  double Lon2Radians = Radians(Lon2Degrees);
    
  double a = Lon1Radians - Lon2Radians;
    
  if (a < 0.0)
  {
    a = -a;
  }
    
  if (a > Math.PI)
  {
    a = 2.0 * Math.PI - a;
  }
    
  return Math.Acos(
        Math.Sin(Lat2Radians) * Math.Sin(Lat1Radians) + 
        Math.Cos(Lat2Radians) * Math.Cos(Lat1Radians) * Math.Cos(a)
        );
}

public static double Radians(double degrees)
{
  return degrees * Math.PI / 180.0;
}
Keywords: Angle, Latitude, Longitude

Reader Comments

Comment on this Blog Post

Recent Posts

TitleDate
.NET Public-Key (Asymmetric) Cryptography DemoJuly 20, 2025
Raspberry Pi 3B+ Photo FrameJune 17, 2025
EBTCalc (Android) Version 1.53 is now availableMay 19, 2024
Vault 3 Security EnhancementsOctober 24, 2023
Vault 3 is now available for Apple OSX M2 Mac Computers!September 18, 2023
Vault (for Desktop) Version 0.77 ReleasedMarch 26, 2023
EBTCalc (Android) Version 1.44 is now availableOctober 12, 2021