title: Issue with calculating compass bearing between two GPS coordinates
body: <p>In my webapp, have a JSON data response from a database query that includes the lat/long coordinates of 1 to n locations.  I want to calculate the bearing from the <code>data[i]</code> location to the current position.</p>
  
  <p>I've been adapting the code <a href="http://www.movable-type.co.uk/scripts/latlong.html" rel="noreferrer">here</a>, but the bearing returned is incorrect.</p>
  
  <pre><code>//starting lat/long along with converting lat to rads
  var endLat = toRad(location.lat());        
  var endLong = location.lng();
  
  //loop over response, calculate new headings for links and add link to array
  for(var i=0; i&lt;data.length; i++){
  
    //this link's lat/long coordinates, convert lat to rads
    var startLat = toRad(data[i].lat);
    var startLong = data[i].lon;
  
    //get the delta values between start and end coordinates in rads
    var dLong = toRad(endLong - startLong);
  
    //calculate 
    var y = Math.sin(dLong)*Math.cos(endLong);
    var x = Math.cos(startLat)*Math.sin(endLat)-Math.sin(startLat)*Math.cos(endLat)*Math.cos(dLong);
    var bearing = Math.atan(y, x);
    bearing = (toDeg(bearing) + 360) % 360;
  
    panoLinks.push({'heading': bearing, 'description': data[i].description, 'pano': data[i].description});
  }
  
  //radian/degree conversions
  function toRad(convert){
    return convert * Math.PI/180;
  }
  
  function toDeg(convert){
    return convert * 180/Math.PI;
  }
  </code></pre>
  
  <p>Using the functions above and the values</p>
  
  <pre><code>startLat= 43.6822, converts to 0.7623982145146669 radians
  startLong= -70.450769
  
  endLat= 43.682211, converts to 0.7623984065008848 radians
  endLong= -70.45070
  
  dLong = startLong - endLong, converts to 0.0000011170107216805305 radians
  </code></pre>
  
  <p>results in a compass degree of </p>
  
  <pre><code>bearing= 0.000014910023935499339
  </code></pre>
  
  <p>which is definitely off.  Where have I gone wrong?</p>