1 | function distance(lat1, lon1, lat2, lon2) {
var R = 6371;
var dLat = deg2rad(lat2 - lat1);
var dLon = deg2rad(lon2 - lon1);
var a =
Math.sin(dLat/2) * Math.sin(dLat/2) +
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
Math.sin(dLon/2) * Math.sin(dLon/2);
var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
var d = R * c;
return d;
}
distance(48, -122, 49, -121);
| ready |
2 | function distance(lat1, lon1, lat2, lon2) {
var R = 6371;
var dLat = deg2rad(lat2 - lat1);
var dLon = deg2rad(lon2 - lon1);
var a =
0.5 - Math.cos(dLat)/2 +
Math.cos(deg2rad(lat1)) * Math.cos(deg2rad(lat2)) *
(1 - Math.cos(dLon))/2;
return R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
}
distance(48, -122, 49, -121);
| ready |
3 | function distance(lat1, lon1, lat2, lon2) {
var R = 6371;
var dLat = (lat2 - lat1) * Math.PI / 180;
var dLon = (lon2 - lon1) * Math.PI / 180;
var a =
0.5 - Math.cos(dLat)/2 +
Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) *
(1 - Math.cos(dLon))/2;
return R * 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
}
distance(48, -122, 49, -121);
| ready |
4 | function distance(lat1, lon1, lat2, lon2) {
var R = 6371;
var dLat = (lat2 - lat1) * Math.PI / 180;
var dLon = (lon2 - lon1) * Math.PI / 180;
var a =
0.5 - Math.cos(dLat)/2 +
Math.cos(lat1 * Math.PI / 180) * Math.cos(lat2 * Math.PI / 180) *
(1 - Math.cos(dLon))/2;
return R * 2 * Math.asin(Math.sqrt(a));
}
distance(48, -122, 49, -121);
| ready |
5 | function distance(lat1, lon1, lat2, lon2) {
var dLat = (lat2 - lat1) * pi180;
var dLon = (lon2 - lon1) * pi180;
var a = 0.5 - Math.cos(dLat)/2 + Math.cos(lat1 * pi180) * Math.cos(lat2 * pi180) * (1 - Math.cos(dLon))/2;
return R * 2 * Math.asin(Math.sqrt(a));
}
distance(48, -122, 49, -121);
| ready |