from math import pi, asin, cos, sin, sqrt def spherical_distance(a, b): coef = pi / 180 radlat1 = a[1] * coef radlat2 = b[1] * coef radlng1 = a[0] * coef radlng2 = b[0] * coef a = sin((radlat1 - radlat2)/2)**2 b = cos(radlat1) * cos(radlat2) * sin((radlng1 - radlng2)/2) ** 2 return asin(sqrt(a+b)) def ang_distance(a, b): x = abs(a-b) return min(x, 360-x)