Haversine formula ?
[quote:39itocod]Haversine formula:
a = sin²(?f/2) + cos f1 · cos f2 · sin²(??/2)
c = 2 · atan2( va, v(1-a) )
d = R · c
where f is latitude, ? is longitude, R is earth’s radius (mean radius = 6,371km);
note that angles need to be in radians!
Radians = Degrees * PI / 180
JavaScript:
var R = 6371e3; // metres
var f1 = lat1.toRadians();
var f2 = lat2.toRadians();
var ?f = (lat2-lat1).toRadians();
var ?? = (lon2-lon1).toRadians();
var a = Math.sin(?f/2) * Math.sin(?f/2) +
Math.cos(f1) * Math.cos(f2) *
Math.sin(??/2) * Math.sin(??/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;