qiblah.si

Method

How the Qibla is calculated

The Qibla is the direction of the Kaaba in Makkah, which Muslims face in prayer (Google, Qibla Finder help). Finding it from anywhere on Earth is a question of spherical geometry, followed by a practical question: which way is north where you stand?

1. The shortest path is a great circle

On a globe, the shortest route between two points follows a great circle, a circle whose center is the center of the Earth. A straight line on a flat Mercator map is not the same thing, which is why the Qibla from New York points north-east, not south-east. Google's Qibla Finder takes the same great-circle approach (source).

2. The initial bearing

The direction you face is the initial bearing of that great circle at your location. With your latitude φ1, the Kaaba's latitude φ2, and the difference in longitude Δλ, the bearing θ is:

θ = atan2( sin Δλ · cos φ₂ ,
           cos φ₁ · sin φ₂ − sin φ₁ · cos φ₂ · cos Δλ )

The result is normalised to 0 to 360 degrees, clockwise from true north. This is the formula documented by Movable Type Scripts, which also notes that the bearing changes as you travel along a great circle; only the starting direction matters for prayer.

3. The distance

Distance uses the haversine formula with a mean Earth radius of 6,371.0088 km (Movable Type Scripts explains the method). The spherical model is an approximation; precise ellipsoidal calculations can give slightly different results. Displayed precision is not a guarantee of sensor accuracy.

4. The reference point

qiblah.si uses its own reference coordinates for the Kaaba: 21.422487° N, 39.826206° E. Other services use slightly different points. From a city thousands of kilometres away, a difference of tens of metres at the Kaaba changes the bearing by far less than a hundredth of a degree.

5. True north versus magnetic north

Bearings here are from true north, the direction of the geographic pole. A magnetic compass differs by the local magnetic declination, sometimes several degrees. Look up declination with NOAA's magnetic field calculator when correcting a magnetic reading. qiblah.si uses device compass or absolute orientation readings when available; these are not guaranteed to be corrected to true north on every device. Cross-check with a true-north reference if readings disagree.

6. Calibrating a phone compass

  • Move the phone slowly in a figure eight a few times, as Google also recommends (source).
  • Step away from metal furniture, cars, speakers and electronics.
  • Remove magnetic cases and mounts.
  • Hold it flat and let the reading settle.

Worked example

From central Lahore (31.5204° N, 74.3587° E) the formula gives 260.4°, a little south of due west, and a distance of 3,598 km.

Open the live Qibla finder