All Downloads are FREE. Search and download functionalities are using the official Maven repository.

lzam.geo-distance.1.0.2.source-code.GeoDistance Maven / Gradle / Ivy

Go to download

Simple library to calculate the geographical distance between two points. Project related to an academic assignment about publishing to Maven Central.

The newest version!
public class GeoDistance {

    private static final double earthRadius = 6371e3;

    public static double haversineDistanceInM(Coordinate start, Coordinate end){
        double lat1 = Math.toRadians(start.getLatitude());
        double lat2 = Math.toRadians(end.getLatitude());
        double deltaLat = Math.toRadians(end.getLatitude() - start.getLatitude());
        double deltaLng = Math.toRadians(end.getLongitude() - start.getLongitude());

        double a = Math.pow(Math.sin(deltaLat/2), 2) + Math.cos(lat1) * Math.cos(lat2) * Math.pow(Math.sin(deltaLng/2), 2);
        double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
        return earthRadius * c;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy