Javascript Number toRad()

Description

Javascript Number toRad()


Number.prototype.toRad = function() {
  return this * Math.PI / 180;
}

Javascript Number toRad()

Number.prototype.toRad = function () { 
  return this * Math.PI / 180;
}

function distanceTwoGeoPoints(lat1, lon1, lat2, lon2) {
 var R = 6371; // Radio medio de la tierra (km)
 var dLat = (lat2 - lat1).toRad();
 var dLon = (lon2 - lon1).toRad();
 var lat1 = lat1.toRad();
 var lat2 = lat2.toRad();
 var a = Math.pow(Math.sin(dLat/2), 2) + Math.pow(Math.sin(dLon/2), 2) * Math.cos(lat1) * Math.cos(lat2); 
 var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
  var d = R * c * 1000; // Distancia (m)
 return d;/*w w w .  jav a 2  s .  c o  m*/
}

Javascript Number toRad()

Number.prototype.toRad = function() {
   return this * Math.PI / 180;
}

Number.prototype.toDeg = function() {
   return this * 180 / Math.PI;
}

google.maps.LatLng.prototype.getHeading = function(point) {
   var lat1 = this.lat().toRad(), lat2 = point.lat().toRad();
   var dLon = (point.lng() - this.lng()).toRad();

   var y = Math.sin(dLon) * Math.cos(lat2);
   var x = Math.cos(lat1) * Math.sin(lat2) -
           Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon);

   var brng = Math.atan2(y, x);

   return ((brng.toDeg() + 360) % 360);
}

Javascript Number toRad()

Number.prototype.toRad = function () {
 return this * Math.PI / 180;
};

function haversine (lat1 , lon1 , lat2 , lon2) {
 var R = 6371;/*  www . j  a  v a 2s .  c  o  m*/
 // km
 //has a problem with the .toRad() method below.
 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);
 var c = 2 * Math.atan2(Math.sqrt(a) , Math.sqrt(1 - a));
 var d = R * c;
}

exports.distance = haversine;

Javascript Number toRad()

/* script using harvesine formula to calculate
    the greatest circle distance bt two points */

Number.prototype.toRad = function() {
    return this * Math.PI / 180;
};

function calculateDistance(start, end) {
    var lat1 = start.lat();
    var lon1 = start.lng();
    var endLoc = end.geometry.location;
    var lat2 = endLoc.lat();
    var lon2 = endLoc.lng();

    // var R = 6371; // km
    var R = 3959; // miles
    var dLat = (lat2-lat1).toRad();
    var dLon = (lon2-lon1).toRad();
    var rLat1 = lat1.toRad();
    var rLat2 = lat2.toRad();

    var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
            Math.sin(dLon/2) * Math.sin(dLon/2) * Math.cos(rLat1) * Math.cos(rLat2);
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    return R * c;
}

Javascript Number toRad()

// Google Maps LatLng Distance Shim
// http://stackoverflow.com/questions/2637023/how-to-calculate-the-latlng-of-a-point-a-certain-distance-away-from-another
Number.prototype.toRad = function() {
 return this * Math.PI / 180;
};

Number.prototype.toDeg = function() {
 return this * 180 / Math.PI;
};



PreviousNext

Related