from math import sin, cos, radians, atan2, sqrt


def haversinedist(loc1, loc2):
    """Returns the haversine great circle distance (in meters) between two locations.
    The input locations must be given as ``(lat, long)`` pairs (decimal values).

    See http://en.wikipedia.org/wiki/Haversine_formula
    """
    lat1, lon1 = loc1
    lat2, lon2 = loc2
    R = 6378100.0 # mean radius of earth, in meters
    dlat = radians(lat2-lat1)
    dlon = radians(lon2-lon1)
    sdlat2 = sin(dlat/2)
    sdlon2 = sin(dlon/2)
    a = sdlat2*sdlat2 + cos(radians(lat1))*cos(radians(lat2))*sdlon2*sdlon2
    d = R * 2 * atan2(sqrt(a), sqrt(1-a))
    return d