From 523ff6a4a6f0040c2623a414ac9f61293615bf10 Mon Sep 17 00:00:00 2001 From: Selim Eser <2211482@stud.hs-mannheim.de> Date: Sun, 9 Jun 2024 17:54:58 +0200 Subject: [PATCH] Changed destination formula to Haversine and multiplied return distance by 1.25 for distance using the streets --- src/main/java/de/hs_mannheim/domain/System.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/hs_mannheim/domain/System.java b/src/main/java/de/hs_mannheim/domain/System.java index 5d8c180..897cf8e 100644 --- a/src/main/java/de/hs_mannheim/domain/System.java +++ b/src/main/java/de/hs_mannheim/domain/System.java @@ -233,7 +233,14 @@ public class System { } } catch (Exception e) {} - return "" + (Math.acos(Math.sin(lat1) * Math.sin(lat2) + Math.cos(lat1) * Math.cos(lat2) * Math.cos(lon2 - lon1)) * 111.324) + " km"; + double dLat = lat2-lat1; + double dLon = lon2-lon1; + + double a = Math.pow(Math.sin(Math.toRadians(dLat/2.0)), 2) + Math.pow(Math.sin(Math.toRadians(dLon/2.0)), 2) * Math.cos(Math.toRadians(lat1)) * Math.cos(Math.toRadians(lat2)); + + double distance = 6378.388 * 2.0 * Math.atan2(Math.sqrt(a), Math.sqrt(1.0-a)); + + return "" + (distance * 1.25) + " km"; }