'Calculate the shortest distance (in km) over the earth\'s sphere between 2 points
Formulae from: http://www.movable-type.co.uk/scripts/latlong.html
(NB We could also use PostGIS functions, where possible, instead of this query)'

@staticmethod
def greatCircleDistance(lat1, lon1, lat2, lon2, quick=True):

    import math
    cos = math.cos
    sin = math.sin
    radians = math.radians
    if quick:
        lat1 = radians(lat1)
        lat2 = radians(lat2)
        lon1 = radians(lon1)
        lon2 = radians(lon2)
        distance = (math.acos(((sin(lat1) * sin(lat2)) + ((cos(lat1) * cos(lat2)) * cos((lon2 - lon1))))) * RADIUS_EARTH)
        return distance
    else:
        sqrt = math.sqrt
        pow = math.pow
        dLat = radians((lat2 - lat1))
        dLon = radians((lon2 - lon1))
        a = (pow(sin((dLat / 2)), 2) + ((cos(radians(lat1)) * cos(radians(lat2))) * pow(sin((dLon / 2)), 2)))
        c = (2 * math.atan2(sqrt(a), sqrt((1 - a))))
        distance = (RADIUS_EARTH * c)
        return distance
