title: Bearing from one coordinate to another
body: <p>I implemented the "bearing" formula from <a href="http://www.movable-type.co.uk/scripts/latlong.html">http://www.movable-type.co.uk/scripts/latlong.html</a>. But it seems highly inaccurate - I suspect some mistakes in my implementation. Could you help me with finding it? My code is below:</p>
  
  <pre><code>protected static double bearing(double lat1, double lon1, double lat2, double lon2){
  
  double longDiff= lon2-lon1;
  double y = Math.sin(longDiff)*Math.cos(lat2);
  double x = Math.cos(lat1)*Math.sin(lat2)-Math.sin(lat1)*Math.cos(lat2)*Math.cos(longDiff);
  
  return Math.toDegrees((Math.atan2(y, x))+360)%360;
  }
  </code></pre>