title: Universal Logic for finding qibla direction
body: <p>I am very keen on knowing an universal qibla direction logic as I want to implement in my islamic android app. I have just obtained latitude and longitude of the user and irrespective of any lat, lon I want to find qibla direction for that person whether the person is in UK, US, India, Sri Lanka or any where.</p>
  
  <p>I found this formula, and don't know how exactly it works:</p>
  
  <pre><code>float lonDelta = (lon2 - lon1);
  float y = Math.sin(lonDelta) * Math.cos(lat2);
  float x = Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(lonDelta);
  float brng = Math.atan2(y, x).toDeg();
  </code></pre>
  
  <p>Please help me in knowing exact formula.</p>