@Test public void testGetDistanceBetweenPointsBigDistance() throws Exception { GpsPoint p1 = new GpsPoint(40.6892, -74.0444); GpsPoint p2 = new GpsPoint(48.8583, 2.2945); AsTheCrowFliesDistanceCalculator cal = new AsTheCrowFliesDistanceCalculator(); double distance = cal.getDistanceBetweenPoints(p1, p2); double expectedDistance = 5837 * 1000; double tolerance = 2 * expectedDistance / 100; assertEquals(expectedDistance, distance, tolerance); }
public double getDistanceBetweenPoints(GpsPoint p1, GpsPoint p2) { double dLat = Math.toRadians(p2.getLatitude() - p1.getLatitude()); double dLon = Math.toRadians(p2.getLongitude() - p1.getLongitude()); double lat1 = Math.toRadians(p1.getLatitude()); double lat2 = Math.toRadians(p2.getLatitude()); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double distance = EARTH_RADIUS * c; return distance; }
AsTheCrowFliesDistanceCalculator implements DistanceCalculator { public double getDistanceBetweenPoints(GpsPoint p1, GpsPoint p2) { double dLat = Math.toRadians(p2.getLatitude() - p1.getLatitude()); double dLon = Math.toRadians(p2.getLongitude() - p1.getLongitude()); double lat1 = Math.toRadians(p1.getLatitude()); double lat2 = Math.toRadians(p2.getLatitude()); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double distance = EARTH_RADIUS * c; return distance; } }
AsTheCrowFliesDistanceCalculator implements DistanceCalculator { public double getDistanceBetweenPoints(GpsPoint p1, GpsPoint p2) { double dLat = Math.toRadians(p2.getLatitude() - p1.getLatitude()); double dLon = Math.toRadians(p2.getLongitude() - p1.getLongitude()); double lat1 = Math.toRadians(p1.getLatitude()); double lat2 = Math.toRadians(p2.getLatitude()); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double distance = EARTH_RADIUS * c; return distance; }  }
AsTheCrowFliesDistanceCalculator implements DistanceCalculator { public double getDistanceBetweenPoints(GpsPoint p1, GpsPoint p2) { double dLat = Math.toRadians(p2.getLatitude() - p1.getLatitude()); double dLon = Math.toRadians(p2.getLongitude() - p1.getLongitude()); double lat1 = Math.toRadians(p1.getLatitude()); double lat2 = Math.toRadians(p2.getLatitude()); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double distance = EARTH_RADIUS * c; return distance; }  double getDistanceBetweenPoints(GpsPoint p1, GpsPoint p2); }
AsTheCrowFliesDistanceCalculator implements DistanceCalculator { public double getDistanceBetweenPoints(GpsPoint p1, GpsPoint p2) { double dLat = Math.toRadians(p2.getLatitude() - p1.getLatitude()); double dLon = Math.toRadians(p2.getLongitude() - p1.getLongitude()); double lat1 = Math.toRadians(p1.getLatitude()); double lat2 = Math.toRadians(p2.getLatitude()); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.sin(dLon / 2) * Math.sin(dLon / 2) * Math.cos(lat1) * Math.cos(lat2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); double distance = EARTH_RADIUS * c; return distance; }  double getDistanceBetweenPoints(GpsPoint p1, GpsPoint p2);  }