Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
First solution in Uncategorized category for Earth Distances by Moff
import re
import math
def angle(src):
g, m, s, d = re.match('(\d+)°(\d+)′(\d+)″(S|N|E|W)', src).groups()
a = int(g) + int(m) / 60 + int(s) / 3600
if d in 'SW':
a *= -1
return math.radians(a)
def distance(a, b):
(lat1, long1), (lat2, long2) = (
(angle(c) for c in z.replace(',', ' ').split()) for z in (a, b))
cl1 = math.cos(lat1)
cl2 = math.cos(lat2)
sl1 = math.sin(lat1)
sl2 = math.sin(lat2)
cdelta = math.cos(long2 - long1)
sdelta = math.sin(long2 - long1)
y = math.sqrt(math.pow(cl2 * sdelta, 2) + \
math.pow(cl1 * sl2 - sl1 * cl2 * cdelta, 2))
x = sl1 * sl2 + cl1 * cl2 * cdelta
ad = math.atan2(y, x)
return ad * 6371 # 6372.795 !!!
Aug. 20, 2015