Nodejs Utililty Methods Distance Calculate

List of utility methods to do Distance Calculate

Description

The list of methods to do Distance Calculate are organized into topic(s).

Method

haversineDistance(lat1, lng1, lat2, lng2)
var haversineDistance(lat1, lng1, lat2, lng2) {
    var R = 6371; 
    var deltaLat = (lat2-lat1).inRadians();
    var deltaLng = (lng2-lng1).inRadians();
    var a = (Math.sin(deltaLat/2) * Math.sin(deltaLat/2)) + (Math.cos(lat1.inRadians()) * Math.cos(lat2.inRadians()) *
                   Math.sin(deltaLng/2) * Math.sin(deltaLng/2));
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    return R * c; 
haversineDistance(lat1, lon1, lat2, lon2)
function haversineDistance(lat1, lon1, lat2, lon2){
  var R = 6371; 
  var x1 = lat2-lat1;
  var dLat = x1.toRad();  
  var x2 = lon2-lon1;
  var dLon = x2.toRad();  
  var a = Math.sin(dLat/2) * Math.sin(dLat/2) + 
  Math.cos(lat1.toRad()) * Math.cos(lat2.toRad()) * 
  Math.sin(dLon/2) * Math.sin(dLon/2);  
...