Need help calculating geographical distance
<p>I'm setting up a small program to take 2 geographical coordinates from a user and then calculate the distance between them(taking into account the curvature of the earth). So I looked up wikipedia on what the formula is <a href="http://en.wikipedia.org/wiki/Great-circle_distance" rel="nofollow">here</a>. </p>

<p>I basically set up my python function based on that and this is what I came up with:</p>

<pre><code>def geocalc(start_lat, start_long, end_lat, end_long):
    start_lat = math.radians(start_lat)
    start_long = math.radians(start_long)
    end_lat = math.radians(end_long)
    end_long = math.radians(end_long)

    d_lat = start_lat - end_lat
    d_long = start_long - end_long

    EARTH_R = 6372.8

    c = math.atan((math.sqrt( (math.cos(end_lat)*d_long)**2 +( (math.cos(start_lat)*math.sin(end_lat)) - (math.sin(start_lat)*math.cos(end_lat)*math.cos(d_long)))**2)) / ((math.sin(start_lat)*math.sin(end_lat)) + (math.cos(start_lat)*math.cos(end_lat)*math.cos(d_long))) )

    return EARTH_R*c
</code></pre>

<p>The problem is that the results come out really inaccurate. I'm new to python so some help or advice would be greatly appreciated! </p>
