public static Angle greatCircleDistance(LatLon p1,LatLon p2){
  if ((p1 == null) || (p2 == null)) {
    throw new IllegalArgumentException("Lat Lon Is Null");
  }
  double lat1=p1.getLatitude().radians;
  double lon1=p1.getLongitude().radians;
  double lat2=p2.getLatitude().radians;
  double lon2=p2.getLongitude().radians;
  if (lat1 == lat2 && lon1 == lon2)   return Angle.ZERO;
  double a=Math.sin((lat2 - lat1) / 2.0);
  double b=Math.sin((lon2 - lon1) / 2.0);
  double c=a * a + +Math.cos(lat1) * Math.cos(lat2) * b* b;
  double distanceRadians=2.0 * Math.asin(Math.sqrt(c));
  return Double.isNaN(distanceRadians) ? Angle.ZERO : Angle.fromRadians(distanceRadians);
}

public static Angle greatCircleDistance ( LatLon p1 , LatLon p2 ) { if ( ( p1 == null ) || ( p2 == null ) ) { throw new IllegalArgumentException ( "Lat Lon Is Null" ) ; } double lat1 = p1 . getLatitude ( ) . radians ; double lon1 = p1 . getLongitude ( ) . radians ; double lat2 = p2 . getLatitude ( ) . radians ; double lon2 = p2 . getLongitude ( ) . radians ; if ( lat1 == lat2 && lon1 == lon2 ) return Angle . ZERO ; double a = Math . sin ( ( lat2 - lat1 ) / 2.0 ) ; double b = Math . sin ( ( lon2 - lon1 ) / 2.0 ) ; double c = a * a + + Math . cos ( lat1 ) * Math . cos ( lat2 ) * b * b ; double distanceRadians = 2.0 * Math . asin ( Math . sqrt ( c ) ) ; return Double . isNaN ( distanceRadians ) ? Angle . ZERO : Angle . fromRadians ( distanceRadians ) ; }
computes the great circle angular distance between two locations . the return value gives the distance as the angle between the two positions on the pi radius circle . in radians , this angle is also the arc length of the segment between the two positions on that circle . to compute a distance in meters from this value , multiply it by the radius of the globe .
