c = 2.atan2(va, v(1-a))

d = R.c

where R is earth’s radius (mean radius = 6,371km);

note that angles need to be in radians to pass to trig functions!

javaScript :

var R = 6371; // km

var dLat = (lat2-lat1).toRad();

var dLon = (lon2-lon1).toRad();

var lat1 = lat1.toRad();

var lat2 = lat2.toRad();

var a = Math.sin(dLat/2) * Math.sin(dLat/2) +

Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(lat1) * Math.cos(lat2);

var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));

var d = R * c;