public double greatCircleDistance(Location location){
  if (location == null) {
    throw new IllegalArgumentException(Logger.logMessage(Logger.ERROR,"Location","greatCircleDistance","missingLocation"));
  }
  double lat1Radians=Math.toRadians(this.latitude);
  double lon1Radians=Math.toRadians(this.longitude);
  double lat2Radians=Math.toRadians(location.latitude);
  double lon2Radians=Math.toRadians(location.longitude);
  if (lat1Radians == lat2Radians && lon1Radians == lon2Radians) {
    return 0;
  }
  double a=Math.sin((lat2Radians - lat1Radians) / 2.0);
  double b=Math.sin((lon2Radians - lon1Radians) / 2.0);
  double c=a * a + Math.cos(lat1Radians) * Math.cos(lat2Radians) * b* b;
  double distanceRadians=2.0 * Math.asin(Math.sqrt(c));
  return Double.isNaN(distanceRadians) ? 0 : distanceRadians;
}

public double greatCircleDistance ( Location location ) { if ( location == null ) { throw new IllegalArgumentException ( Logger . logMessage ( Logger . ERROR , "Location" , "greatCircleDistance" , "missingLocation" ) ) ; } double lat1Radians = Math . toRadians ( this . latitude ) ; double lon1Radians = Math . toRadians ( this . longitude ) ; double lat2Radians = Math . toRadians ( location . latitude ) ; double lon2Radians = Math . toRadians ( location . longitude ) ; if ( lat1Radians == lat2Radians && lon1Radians == lon2Radians ) { return 0 ; } double a = Math . sin ( ( lat2Radians - lat1Radians ) / 2.0 ) ; double b = Math . sin ( ( lon2Radians - lon1Radians ) / 2.0 ) ; double c = a * a + Math . cos ( lat1Radians ) * Math . cos ( lat2Radians ) * b * b ; double distanceRadians = 2.0 * Math . asin ( Math . sqrt ( c ) ) ; return Double . isNaN ( distanceRadians ) ? 0 : distanceRadians ; }
computes the angular distance of the great circle path between this location and a specified location . in radians , this angle is the arc length of the segment between the two locations . to compute a distance in meters from this value , multiply the return value by the radius of the globe . this function uses a spherical model , not elliptical .
