import math


def haversine(coord1, coord2):
    """use the Haversine function to determine the distance between two points 
    in the WGS84 coordinate system. Returns the distance between the two points 
    in meters.
    Source: https://janakiev.com/blog/gps-points-distance-python/

    coord1:     (lat, lon) coordinates of first point
    coord2:     (lat, lon) coordinates of second point
    """
    R = 6372800
    lat1, lon1 = coord1
    lat2, lon2 = coord2

    phi1, phi2 = math.radians(lat1), math.radians(lat2)
    dphi = math.radians(lat2 - lat1)
    dlambda = math.radians(lon2 - lon1)

    a = (
        math.sin(dphi / 2) ** 2
        + math.cos(phi1) * math.cos(phi2) * math.sin(dlambda / 2) ** 2
    )

    return 2 * R * math.atan2(math.sqrt(a), math.sqrt(1 - a))