C, Calculating the distance between two GPS locations? -


if have 2 gps locations, 51.507222, -0.1275 , 48.856667, 2.350833, formula use calculate distance between two? i've heard lot haversine formula, can't find information it, or how apply c.

i've written following code, however, it's innacurate. know why? can't figure out. problem comes function itself, don't know is.

float calcdistance(float a, float b, float c, float d)  {     float dlat;     float dlon;     dlat = (c - a);     dlon = (d - b);     dlat /= 57.29577951;     dlon /= 57.29577951;      float v_a;     float v_c;     float distance;      v_a = sin(dlat/2) * sin(dlat/2) + cos(a) * cos(c) * sin(dlon/2) * sin(dlon/2);     v_c = 2 * atan2(sqrt(v_a),sqrt(1-v_a));     distance = r * v_c;     return distance; } 

this page has block of javascript i'm sure adapt enough in c:

var r = 6371e3; // metres var φ1 = lat1.toradians(); var φ2 = lat2.toradians(); var Δφ = (lat2-lat1).toradians(); var Δλ = (lon2-lon1).toradians();  var = math.sin(Δφ/2) * math.sin(Δφ/2) +         math.cos(φ1) * math.cos(φ2) *         math.sin(Δλ/2) * math.sin(Δλ/2); var c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a));  var d = r * c; 

Comments

Popular posts from this blog

Python __call__ special method practical example -

How can I edit my VIM config so that Vim treats ".ejs" files the same as it currently treats my html files? -