title: using the haversine formula in javascript with variables
body: <p>hi i have been struggling with using the have sine formula to get the distance between the users current location and objects in an array, i have found a great answer to this question but when i try to use variables instead of actual coordinates the formula dosent work, hopefully some one will know where i am going wrong </p>
  
  <p>this is the question that got me to this point, thank you Talkol for your answer</p>
  
  <p><a href="https://stackoverflow.com/questions/14560999/using-the-haversine-formula-in-javascript">Using the Haversine Formula in Javascript</a></p>
  
  <p>this is what I've got so far</p>
  
  <pre><code>  navigator.geolocation.getCurrentPosition (function (posa)
  {
    var lat = posa.coords.latitude.toFixed(6);
    var lng = posa.coords.longitude.toFixed(6);
  
  });
  
      function getCurrent() {
  
  var lat1 = lat; 
  var lon1 = lng;
  
  var lat2 = 42.741; 
  var lon2 = -71.3161; 
  
  Number.prototype.toRad = function() {
     return this * Math.PI / 180;
  }
   var R = 6371; // 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; 
  
  alert(d);
  var distance = d
  
  $("#distance").val (distance);
  }
  </code></pre>