
Hi,
I'm writing a simple app to (amongst other things) show the distance between two GPS points. This distance will typically be under 500m (locating a downed quadcopter), and I'm trying to implement the Haversine formula. I've read through all of the previous mentions of this but haven't found the answer.
I'm using the formula here:
http://rosettacode.org/wiki/Haversine_formula#PythonPython version:
def haversine(lat1, lon1, lat2, lon2):
R = 6372.8 # Earth radius in kilometers
dLat = radians(lat2 - lat1)
dLon = radians(lon2 - lon1)
lat1 = radians(lat1)
lat2 = radians(lat2)
a = sin(dLat/2)**2 + cos(lat1)*cos(lat2)*sin(dLon/2)**2
c = 2*asin(sqrt(a))
return R * c
>>> haversine(36.12, -86.67, 33.94, -118.40)
2887.2599506071106
I convert the coordinates to radians before passing these values to the attached blocks, and as far as I can see, it's working ok until it gets to the lines calculating a,b,c.
(I split it up in order to try and trace the steps). However, the values returned are nowhere near the example above, or other distances calculated (say) on google maps.
Can anyone see where I've gone wrong? Thanks for any advice, Dave