Interactive tool
Calculate the Qibla for any place, step by step
Pick a city or type any coordinates. The globe, the compass and every step of the formula update together. Lahore is the worked example; each step is explained in the sections below.
Qibla Explorer
Tap the globe. Watch the Qibla move.
True north · magnetic north 2.2° E · Qibla θ
A straight line on a flat map would point 8.5° away from the true Qibla. The Earth is round, so the shortest path bends: we use the great circle.
Show the maths for Lahore
| Step | Formula | Value |
|---|---|---|
| Your position φ₁, λ₁ | GPS or city centre | 31.5204°, 74.3587° |
| Kaaba φ₂, λ₂ | fixed reference, WGS 84 | 21.4225°, 39.8262° |
| Δλ | λ₂ − λ₁ | −34.5325° |
| y | sin Δλ · cos φ₂ | −0.52771 |
| x | cos φ₁ · sin φ₂ − sin φ₁ · cos φ₂ · cos Δλ | −0.08958 |
| θ | atan2(y, x) | −99.634° |
| Qibla | (θ + 360°) mod 360° | 260.366° |
| Shown | rounded to 0.1°, in words | 260.4° · 9.6° south of west |
| a | sin²(Δφ/2) + cos φ₁ · cos φ₂ · sin²(Δλ/2) | 0.077656 |
| Distance d | 2R · asin(√a), R = 6,371.0088 km | 3598.4 km |
| Magnetic compass | Qibla − declination | 258.2° |
At a glance
| Target | Centre of the Kaaba, 21.4225° N, 39.8262° E (WGS 84) |
|---|---|
| Your position | Saved city, browser location after you allow it, or a searched city (city centre) |
| Bearing | Initial great-circle bearing on a sphere, clockwise from true north |
| Distance | Haversine, mean Earth radius 6,371.0088 km |
| North on phones | Magnetic heading + declination from the World Magnetic Model (WMM2025) |
| Shown as | Bearing to 0.1°, distance to 1 km, direction in words |
| Runs | In your browser. Your location is not sent to our server. |
1 · The reference point: the Kaaba
The Qibla is the direction of the Kaaba in Al-Masjid al-Haram, Makkah (Quran 2:144). We use the centre of the building: 21.4225° N, 39.8262° E on the WGS 84 datum, the same datum GPS uses.
Four decimal places are about 11 m on the ground. Moving the target point by the full size of the Kaaba changes the bearing from Lahore by far less than 0.01°, so the choice of point inside the building has no visible effect anywhere outside Makkah.
2 · Your position
The page needs one pair of coordinates. It takes them in this order and never guesses from your IP address:
- Saved city. If you saved a city on MiqatLive, we use its centre from our city database (GeoNames).
- Use my location. Only after you tap the button and your browser asks for permission. We use the coordinates and their accuracy radius from the browser’s Geolocation API.
- City search. The centre of the city you pick.
The page HTML is the same for every visitor and for search engines. Nothing about your place is rendered on the server.
3 · The bearing formula
The Qibla is the direction in which the shortest path over the Earth, a great circle, leaves your position toward the Kaaba. This is the initial bearing (forward azimuth):
- φ₁, λ₁: your latitude and longitude. φ₂, λ₂: the Kaaba.
- Δλ = λ₂ − λ₁. Angles in radians inside the functions.
- atan2 keeps the right quadrant, so the result works anywhere on Earth, east or west, north or south of Makkah.
- The result is measured clockwise from true north: 0° north, 90° east, 180° south, 270° west. Lahore: θ = −99.634°, so the Qibla is 260.366°, shown as 260.4°.
4 · Distance to the Kaaba
The distance is the length of the same great circle, from the haversine formula:
Lahore: a = 0.077656, central angle 0.564814 rad, d = 3,598.4 km, shown as 3,598 km. R is the mean radius of the Earth defined by the IUGG.
5 · Sphere or ellipsoid?
The Earth is slightly flattened at the poles. A geodesic on the WGS 84 ellipsoid (Karney’s method) is more exact than a great circle on a sphere. We compared both for ten cities:
| City | Sphere | Ellipsoid | Difference | Distance (sphere · ellipsoid) |
|---|---|---|---|---|
| Lahore | 260.37° | 260.46° | 0.09° | 3,598 · 3,603 km |
| Karachi | 267.74° | 267.79° | 0.04° | 2,800 · 2,804 km |
| Islamabad | 255.91° | 256.02° | 0.11° | 3,528 · 3,531 km |
| Peshawar | 253.99° | 254.10° | 0.11° | 3,401 · 3,405 km |
| Quetta | 256.66° | 256.76° | 0.10° | 2,878 · 2,881 km |
| Dubai | 258.23° | 258.31° | 0.08° | 1,631 · 1,633 km |
| Istanbul | 151.62° | 151.51° | 0.11° | 2,405 · 2,400 km |
| London | 118.99° | 118.87° | 0.12° | 4,794 · 4,795 km |
| Jakarta | 295.15° | 295.02° | 0.13° | 7,920 · 7,922 km |
| New York | 58.48° | 58.40° | 0.09° | 10,306 · 10,324 km |
The difference stays near 0.1°, which is about 2 cm across a 10 m prayer hall and far below what a phone compass can resolve. We use the sphere so that every number can be checked by hand with the formula above. Decision: MiqatLive uses the sphere. You check the Qibla with a phone, and a phone compass is off by several degrees, far more than the 0.1° difference.
6 · True north and magnetic north
The Qibla bearing is measured from true north, the direction of the geographic North Pole. A magnetic compass points to magnetic north. The angle between them is the magnetic declination; it depends on the place and changes slowly every year.
- We take the declination for your coordinates and today’s date from the World Magnetic Model WMM2025, published by NOAA NCEI and the British Geological Survey, valid 2025–2030.
- Where a phone already reports a heading relative to true north, we use it as it is and do not add the declination twice.
- If you use a separate hand compass, set the local declination on it or add it yourself.
7 · The live compass on phones
On a phone the dial turns with you so the Kaaba mark always points at the Qibla. The steps behind it:
- Turn hint. The page shows “turn 12° right” from the difference between the Qibla bearing and your heading.
- Aligned. Within ±3° the gold ring lights up and the phone vibrates once, where the browser supports it.
- Calibration. When the sensor reports low accuracy, the page asks you to move the phone in a figure 8.
- Hold it flat. The heading is most reliable with the screen facing up; tilted phones are corrected but less stable.
- Interference. Steel, cars, speakers, magnets and magnetic phone cases bend the reading by several degrees. No software can remove that.
8 · Desktop and the map
Laptops and desktops have no compass sensor. There the dial shows the bearing with north at the top, and a map draws the great circle from your place to Makkah.
The map is a flat (equirectangular) world map, so the shortest path appears as a curve. The line is drawn from 49 points calculated along the great circle.
9 · Rounding and direction in words
- Bearing to one decimal (260.4°). Distance to the nearest kilometre (3,598 km).
- Direction in words is measured from the nearest cardinal point: 260.4° is 270° − 9.6°, so “9.6° south of west”, written as “about 10° south of due west”.
- All numbers use Western digits on every language version.
10 · Sun, moon and Rasd al-Qibla
Rasd al-Qibla is the moment the sun is directly over the Kaaba: the sun’s declination equals the Kaaba’s latitude (21.4225° N) while the sun crosses Makkah’s meridian. This happens twice a year, around 27–28 May (about 12:17 PM Makkah time) and 15–16 July (about 12:26 PM). At that minute, the shadow of any upright object points directly away from the Qibla, wherever the sun is up.
Around 28 November and 13 January the sun is over the point opposite the Kaaba. Then shadows point toward the Qibla; this is useful in the Americas, where it is daytime.
Our prayer engine computes the exact minute each year from the sun’s position (Meeus, Astronomical Algorithms) and converts it to your local time.
Sun at Dhuhr. At local solar noon the sun is due south (northern hemisphere, outside the tropics). Face it and turn right by (Qibla − 180°). In the tropics and the southern hemisphere the sun can be north at noon; the page adjusts the instruction.
11 · Edge cases
- Inside Al-Masjid al-Haram. Within 1 km of the Kaaba the page says “You are at the Kaaba” instead of a bearing: face the building.
- The opposite point. At 21.4225° S, 140.1738° W in the South Pacific, every direction is a shortest path. Close to it the bearing changes fast; the page warns about this.
- Near the poles. The formula still works; the phone compass becomes unreliable, so the page relies on the bearing and the sun.
- Low location accuracy. If the browser’s accuracy radius is over 5 km, we show it and suggest a city search.
12 · How we test
- A golden table of cities with bearings and distances checked against an independent geodesic library. A release fails if any bearing differs by more than 0.2°.
- Unit tests for both sides of the date line, the southern hemisphere, the poles, the Kaaba itself and its opposite point.
- Field checks on Android and iPhone against the mihrab of known mosques and against Rasd al-Qibla shadows. [Results to be added]
13 · Privacy
- The calculation runs in your browser. Your coordinates and compass readings are not sent to MiqatLive.
- Nothing is stored unless you choose “Save city”; then only the city is kept on your device.
- No location-based redirects; the page is the same for everyone.
14 · Sources
- The Quran, Surah Al-Baqarah 2:142–150 (change of the Qibla, 2:144).
- Sahih al-Bukhari 40 (sixteen or seventeen months toward Bayt al-Maqdis).
- NGA, World Geodetic System 1984 (WGS 84).
- NOAA NCEI and British Geological Survey, World Magnetic Model WMM2025.
- C. F. F. Karney, “Algorithms for geodesics”, Journal of Geodesy 87 (2013).
- J. Meeus, Astronomical Algorithms, 2nd ed. (1998).
- W3C, Geolocation API and DeviceOrientation Event specifications.
- GeoNames, city coordinates.
- Kaaba coordinates: [source to confirm].
15 · Changes to this page
| Date | Change |
|---|---|
| Version 1.0 published. |