| | |
| | | |
| | | return (long) (EARTH_RADIUS * c * 1000); |
| | | } |
| | | public static long calculateDistanceDecinal (BigDecimal lat1, BigDecimal lon1, BigDecimal lat2, BigDecimal lon2) { |
| | | double dLat = Math.toRadians(Constants.formatBigdecimal(lat2).doubleValue() - Constants.formatBigdecimal(lat1).doubleValue()); |
| | | double dLon = Math.toRadians(Constants.formatBigdecimal(lon2).doubleValue() - Constants.formatBigdecimal(lon1).doubleValue() ); |
| | | |
| | | double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + |
| | | Math.cos(Math.toRadians(Constants.formatBigdecimal(lat1).doubleValue())) |
| | | * Math.cos(Math.toRadians(Constants.formatBigdecimal(lat2).doubleValue())) * |
| | | Math.sin(dLon / 2) * Math.sin(dLon / 2); |
| | | double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); |
| | | |
| | | return (long) (EARTH_RADIUS * c ); |
| | | } |
| | | } |