Home Search by Country About us How to use Privacy Contact

How to use the calculated Qibla direction angle with a physical compass or a compass app

The Qibla direction angle is the angle that you need to face in order to pray towards the Kaaba in Mecca. You can use a physical compass or a compass app.
Simply align the needle or the on-screen arrow with magnetic north, and then turn your body until you're facing the correct angle as indicated by our calculation related to your city.
If you're using a physical compass, you may need to adjust for local magnetic declination, which is the difference between magnetic north and true north. This information can usually be found on maps or online.

Calculation Method

  1. Define the coordinates of Mecca, Saudi Arabia:
  2. const meccaLatitude=21.4225;
    const meccaLongitude=39.8262;

  3. Convert the latitude and longitude of the user's location and Mecca to radians:
  4. const lat1=latitude * (Math.PI / 180);
    const lon1=longitude * (Math.PI / 180);
    const lat2=meccaLatitude * (Math.PI / 180);
    const lon2=meccaLongitude * (Math.PI / 180);

  5. Calculate the difference in longitude and latitude between the two points:
  6. const dLon=lon2 - lon1;
    const dLat=lat2 - lat1;

  7. Calculate the qibla direction using the Haversine formula:
  8. const y=Math.sin(dLon) * Math.cos(lat2);
    const x=Math.cos(lat1) * Math.sin(lat2) - Math.sin(lat1) * Math.cos(lat2) * Math.cos(dLon);
    const qibla=Math.atan2(y, x) * (180 / Math.PI);

  9. Normalize the qibla direction to a value between 0 and 360 degrees:
  10. const qiblaNormalized=(qibla + 360) % 360;