import math


def distance_latlon(lat1, lon1, lat2, lon2):
    """
    This calculates the geographic distance between two (lat,lon) coordinate
    pairs. The output is in meters to be consistent with some thresholds
    used later on.
    """
    radius_earth = 6378.137
    d_lat = (lat2 - lat1) * math.pi / 180
    d_lon = (lon2 - lon1) * math.pi / 180
    calc_1 = (math.sin(d_lat/2)**2
              + math.cos(lat1 * math.pi / 180)
              * math.cos(lat2 * math.pi / 180)
              * math.sin(d_lon/2)**2)
    calc_2 = 2*math.atan2(math.sqrt(calc_1), math.sqrt(1-calc_1))
    return radius_earth * calc_2 * 1000