lzam.geo-distance.1.0.1.source-code.GeoDistance Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of geo-distance Show documentation
Show all versions of geo-distance Show documentation
Simple library to calculate the geographical distance between two points. Project related to an academic assignment about publishing to Maven Central.
public class GeoDistance {
private static final double earthRadius = 6371e3;
public static double haversineDistanceInKm(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