/** * Method uses the haversine formulae * to calculate the distance around the * globe from one city to another. * @return - distance in miles */ public double calcDistanceToFly() { double R = 6371000; double lat1 = OriginCity.getLatitude(); double lat2 = destinationcity.getLatitude(); double lon1 = OriginCity.getLongitude(); double lon2 = destinationcity.getLongitude(); double lat1Radians = Math.PI * (lat1); double lat2Radians = Math.PI * (lat2); double lon1Radians = Math.PI * (lon1); double lon2Radians = Math.PI * (lon2); double deltaLat = Math.PI * (lat2 - lat1); double deltaLon = Math.PI * (lon2 - lon1); double a = Math.Pow(Math.Sin(deltaLat / 2), 2) + (Math.Cos(lat1Radians) * Math.Cos(lat2Radians) * Math.Pow(Math.Sin(deltaLon / 2), 2)); double c = 2 * Math.Atan2(Math.Sqrt(a), Math.Sqrt(1 - a)); double distance = R * c; return(distance * 0.000621371); } //end