From f5ce288871fe439a3a86a234f745069392fe748c Mon Sep 17 00:00:00 2001 From: binlaab Date: Tue, 9 Dec 2025 11:43:35 +0100 Subject: [PATCH] error en haversine() --- proyecto/util.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/proyecto/util.py b/proyecto/util.py index b6f0595..3fab26f 100644 --- a/proyecto/util.py +++ b/proyecto/util.py @@ -52,15 +52,15 @@ def convertirMes(mes): def haversine(coord1, coord2): r = 6367.45 * 1000 # conversión a metros + for i in coord1.keys(): + coord1[i] = math.radians(coord1[i]) + coord2[i] = math.radians(coord2[i]) + dlat = coord2['latitud'] - coord1['latitud'] - dlong = coord2['latitud'] - coord1['longitud'] - - dlat = math.radians(dlat) - dlong = math.radians(dlong) - - h = math.sin(dlat)**2 + math.cos(dlat) * math.cos(dlong) * math.sin(dlong)**2 - d = 2 * r * math.asin(math.sqrt(h)) - return d + dlong = coord2['longitud'] - coord1['longitud'] + h = math.sin(dlat / 2)**2 + math.cos(coord1['latitud']) * math.cos(coord2['latitud']) * math.sin(dlong / 2)**2 + d = 2 * math.atan2(math.sqrt(h), math.sqrt(1 - h)) + return d * r def convertirSegundos(instante): try: