Text size
Back to top

The two coordinate pairs used in the calculation

Every result starts from one origin and one fixed target. Both are given as latitude and longitude in decimal degrees. Latitude runs from −90 to 90 and longitude from −180 to 180. Negative values mean south or west, so the Toronto city preset is 43.6532, -79.3832.

Origin
This is the point you choose. Use my location asks the browser for your position once, when you press it. The finder does not keep following your location. You can also choose an origin in any of these ways:
  • pick one of 107 bundled city presets
  • type coordinates under Enter coordinates instead
  • open a shared link that carries a city or coordinates
  • move the optional map and choose Use map centre
A city preset is one approximate point near the city centre. It is not your address or your building. A city that is missing from the presets can still be calculated from its coordinates.
Target
The target is 21.4225241° N, 39.8261818° E. This pair comes from a published reference used in the Adhan JavaScript library, and it was checked as falling inside the Kaaba footprint mapped in OpenStreetMap. This project has not surveyed it independently, and it is not presented as the exact centre of the building.

An initial great-circle bearing on a spherical Earth

On a sphere, the shortest path between two points follows a great circle, which is any circle that divides the globe into two equal halves. The finder reports the direction of that path where it leaves your origin. The compass direction of a great-circle route usually changes along the way, so the initial bearing is usually not a heading you could hold all the way to Makkah. Routes along a meridian or the equator are the exceptions.

θ = atan2( sin Δλ · cos φ2 , cos φ1 · sin φ2 − sin φ1 · cos φ2 · cos Δλ )
bearing = (θ converted to degrees + 360) mod 360
φ1, λ1
Latitude and longitude of the origin
φ2, λ2
Latitude and longitude of the target
Δλ
λ2 − λ1, the difference in longitude
atan2
The two-argument arctangent, which places the angle in the correct quadrant. All angles inside the formula are in radians.

The result is normalised so that 0 ≤ bearing < 360 and measured clockwise from true north. On this scale, 0° is true north, 90° is east, 180° is south and 270° is west.

The Earth is treated as a sphere with a mean radius of 6,371.0088 km. This is a spherical model, not the ellipsoidal geodesic used in some surveying software, so a calculator that models the Earth’s flattening can return a slightly different number.

Distance is calculated separately from the bearing. The finder takes the cross and dot products of the two points’ position vectors and combines them with atan2 to get the central angle between the points, then multiplies that angle by the radius. The result is a surface distance estimate, not a road or flight route. For general background on spherical formulas of this kind, see Movable Type’s latitude/longitude calculations reference.

Why a straight line on a flat map looks different

Many online maps use the Web Mercator projection, which stretches the globe onto a flat rectangle. On such a map a great-circle route can appear curved, and a straight line drawn between the same two points can suggest a different starting angle. From the Calgary city preset, for example, a straight line to Makkah on a Web Mercator map heads generally east or southeast, yet the calculated initial bearing is about 25.0°, north-northeast. Not every route curves visibly on every projection, but when you compare a map with the bearing, look at the direction at your origin, where the great-circle route begins.

The optional map in the finder (Open map) is there for context. Zooming or panning changes the view, not the calculated bearing, and the map cannot sense which way your phone faces. For a fuller explanation, read why routes curve on a map.

Is the Qibla where the sun sets? Not as a general rule, and it is not always west or east either. The direction depends on where you start. From the Toronto preset the calculated bearing is about 54.6°, and from Calgary about 25.0°. Both are east of north, and neither is towards sunset. Words such as “northeast” only summarise the numeric angle.

This finder works from coordinates only. It does not calculate a timetable of solar alignments, and it gives no sunset-based guidance. Do not assume that a shadow at any given moment points towards the Qibla. If you want to consider a shadow-based method, the guide to finding Qibla without a compass sets out that guidance with its sources and qualifications.

True north, magnetic north and declination

The calculated bearing is measured from true north, the direction towards the geographic North Pole. A magnetic compass lines up with the local magnetic field instead. Magnetic declination is the angle between these two directions, and it varies with place and date. NOAA’s World Magnetic Model overview explains this in more detail. In this finder, declination (D) is east-positive: east declination is a positive number and west declination is negative.

Converting between the two references takes a single step in each direction:

  • Magnetic reading to true heading: T = M + D, wrapped to 0–360°.
  • True bearing to a magnetic compass target: M = T − D, wrapped to 0–360°.

These two formulas are inverses. Choose the one that matches your starting value and apply it once. A compass that is already adjusted to true north should use the true bearing as it is. Correcting it again would shift the target by the declination a second time.

Illustrative example: suppose the true bearing is 120° and declination is 10° east (D = +10°). An unadjusted magnetic compass should then point to 110°. With 10° west (D = −10°), the magnetic target is 130°. In both cases, adding D to the magnetic figure returns 120° true. These declination values are for illustration only and are not the current declination for any city. The worked example in this section lets you switch D between east and west and check both conversions.

When the live compass is on, the finder treats the heading reported by the phone as a magnetic heading and applies the same rule to it once. This aligns the phone’s heading reference with true north. It does not turn the phone towards the Qibla. If you are using a handheld compass instead, follow these steps to use a separate compass.

True and magnetic north: a worked example

Suppose the true bearing is 120°. Change declination to see the number you would follow on a magnetic compass.

NESW
True northMagnetic northExample direction
True bearing T
120°
Magnetic target M
110°

T − D = M120° − (+10°) = 110°

Back to true bearing110° + (+10°) = 120°

Illustrative only, not your current declination: switch D between +10° east and −10° west to see M = T − D and M + D = T.

This D value is illustrative, not the current declination at your location.

The tool applies WMM correction only to a heading identified as magnetic. A heading already referenced to true north must not be corrected again. Sign and addition convention: NOAA’s declination guide.

When magnetic correction or live guidance is unavailable

Two separate checks can stop the live arrow. Neither removes the numeric true bearing or the map, as long as the selected point has a valid bearing in the first place (see when no single bearing is shown).

The magnetic model gives no valid correction when:

  • The date is outside the model’s validity in this finder. The bundled World Magnetic Model 2025 (WMM2025) is used from 2025-01-01 00:00 UTC to 2029-11-13 03:00 UTC. NOAA lists the model’s general expiry as 31 December 2029, but this finder stops earlier, at its bundled cutoff.
  • The horizontal magnetic field is weaker than 6,000 nT, which is too weak for a dependable correction.
  • The point is at a geographic pole.
  • The model calculation fails.

The model runs on your device and assumes zero ellipsoid height. Without a valid correction, the finder withholds live true-north alignment. Once a usable heading arrives with the phone level in portrait, the status may read: “A valid magnetic correction is unavailable here. No live true-north alignment is shown.” The checks below are made first, so one of their messages may appear instead.

Live guidance pauses, even when a valid declination is shown, in these cases:

  • Compass permission is off, or the browser does not provide a phone compass.
  • The browser reports only a relative orientation with an unknown starting point. The finder never treats such a reading as true north.
  • The phone is not flat or nearly level, within about 5° on both tilt axes, with the screen in portrait orientation. Landscape orientation or a larger tilt pauses alignment, and the finder asks you to use portrait and hold level.
  • No fresh, usable heading has arrived.

In any of these cases you can still apply the true bearing with an independent reference you trust. The model estimates only the Earth’s main magnetic field. It cannot cancel disturbance from magnetic cases, steel furniture or nearby electronics, and it does not calibrate your phone’s sensor. If the live arrow behaves oddly, troubleshoot changing compass readings.

What limits practical accuracy

How accurate is a Qibla finder? Two different kinds of accuracy are involved. The calculation is precise arithmetic on its inputs and models. How closely you then face that direction in a room depends on several separate sources of uncertainty, each with its own unit. No measured field-accuracy figure for physical alignment is published.

  • Origin. Browser location reports a position-confidence radius in metres, which MDN’s Geolocation accuracy reference describes as a 95% radius. It describes position only, not compass degrees. A value you type into Position uncertainty (metres, optional) is not automatically a 95% figure, and an uncertainty saved earlier or carried in a shared link is not a fresh reading. A blank field does not mean zero error. City presets are approximate by design, and a more specific point is not automatically closer to where you actually stand.
  • Target. The reference pair is published and checked against a mapped footprint, but this project has not surveyed it independently.
  • Models. The Earth is treated as a sphere, and the magnetic model estimates only the main field.
  • Heading. Phone sensors and handheld compasses can drift or be disturbed by metal, magnets and electronics.
  • Applying the result. Lining up a prayer mat or a printed card with a number adds its own error.

When the position uncertainty is small and the point is well away from the Kaaba, its antipode and the geographic poles, a position shift of that size changes the calculated bearing only slightly. Close to the Kaaba or its antipode, the same shift can change the bearing a great deal. Close to a geographic pole, a shift of only a few metres can also change the bearing sharply, because the direction of true north itself changes quickly there, even though the distance to Makkah hardly changes. Extra decimal places in the output do not remove any of these uncertainties. To learn more about what the radius means, read about location uncertainty.

Can the Qibla direction change? From a fixed origin, the calculated true bearing stays the same. It changes only when the origin changes, for example when you pick a different city or a new location reading places you elsewhere. The magnetic target is different: it varies from place to place and shifts over the years as declination changes. With the compass off, the arrow is a north-up bearing and stays still, which is expected. With the live compass on, the arrow should move as you turn the phone. Persistent jitter while the phone is still may point to interference or a sensor problem.

Does the Qibla direction have to be exact? That is a religious question, and this finder does not rule on acceptable deviation. It gives geographic information and states its uncertainties. For guidance on how precise you need to be, ask a scholar or a community you trust.

When no single bearing is shown

A direction from one point to another only makes sense when the two points are separate and not directly opposite each other on the globe. The finder withholds a bearing in three cases.

Cases where the finder shows no bearing
CaseReasonWhat the finder does
Within 25 m of the target, or within the supplied position uncertainty if that is largerAt the reference point there is no direction to give. Very close to it, small position changes swing the direction widely.Shows no bearing and asks you to check your position locally.
Within the same radius of the antipode, about 21.4225° S, 140.1738° W in the South PacificAt the antipode, every great circle from the origin reaches the target over the same distance, so no single shortest path exists. Close to it, the direction is unstable.Shows no bearing.
Exactly at a geographic pole (latitude 90 or −90)A local true-north reference does not exist there.Shows no physical compass direction. There is no extra radius around the poles.

The 25 m figure is a conservative safeguard built into the software. It is not a boundary of the Kaaba, a religious tolerance or a 95% confidence guarantee. If you supply no uncertainty, the finder uses 25 m, but this does not mean your position is exact. Near the Kaaba, follow established local guidance rather than a calculated bearing.

Comparing results and what testing covers

To compare this finder fairly with another calculator, follow these steps:

  1. Enter the same origin coordinates in each calculator, in decimal degrees.
  2. Check which target coordinates each calculator uses.
  3. Confirm the north reference. A magnetic figure differs from a true one by the declination.
  4. Check the Earth model. A spherical calculation and an ellipsoidal one can differ slightly.
  5. Round both numbers to the same precision and compare them before you compare arrows on screen.

If the numbers still differ, these steps usually show you why.

The calculation code is checked against 16 fixed reference cases computed on a sphere with GeographicLib (Python, version 2.1). Further checks cover points near the target, antipodal points, the poles, model dates, weak magnetic fields and magnetic correction. Other tests cover input parsing, shared and saved locations, heading helpers, and the order in which a shared link, a city page or a saved location is loaded at startup. These are software tests only. No physical phone, magnetometer or GPS field testing is claimed.

The bearing calculation and the magnetic model run in your browser, and no camera is used. The finder asks for location and compass access separately, and only when you press Use my location or Enable live compass. Opening the optional map loads tiles from an OpenStreetMap tile service, which receives your IP address and the area you view. A link created with Share location contains its coordinates, label and any supplied uncertainty, so anyone who receives it can see these details, and it can stay in browser history. The privacy page explains these points, along with saving a location on your device.

Qibla Finder Online offers independent geographic guidance. It is not a religious ruling and is not certified by any authority. When you are ready, calculate a bearing for your own starting point.