All writing

Qibla direction on a Mac: how it is calculated without a compass

Qibla direction on a Mac is a great-circle bearing from true north, since Macs have no compass: about 119° from London, 58° from New York.

A Mac knows where it is, but not which way it is facing. So the Qibla direction on a Mac is a number, not a moving needle: the initial bearing of the great circle from your coordinates to the Kaaba, measured clockwise from true north. From central London that is about 119°, a little south of east-south-east. From New York it is about 58°, north-east, which surprises anyone who has looked at a flat map. Turning that number into a direction in the room is a separate step, and it is the one a Mac cannot do for you.

This post works the bearing out by hand, checks it against a second calculator, explains why North America faces north-east, and says what a Mac app can and cannot show. The examples come from PrayerTimes Pro, the studio's menu-bar prayer app, whose Qibla screen draws this bearing on a fixed, north-up dial.

Where the Kaaba is

Every Qibla calculation starts with one coordinate. The English Wikipedia article on the Kaaba gives 21.4225° N, 39.82617° E (21°25′21″ N, 39°49′34″ E), and that is the point used below, rounded to 39.8262° E.

Published figures disagree slightly. The same encyclopedia's Qibla article lists 21.422478° N, 39.825183° E, about 100 metres to the west. At the distances involved that hardly matters: swapping one point for the other moves the bearing from London by 0.001°. The coordinate is not where the error in a Qibla reading comes from.

The formula: an initial bearing on a great circle

The shortest path between two points on a sphere is an arc of a great circle, the circle whose centre is the centre of the Earth. The direction you set off along that arc is its initial bearing, also called the forward azimuth. Chris Veness's Movable Type reference gives it as:

θ = atan2( sin Δλ · cos φ2 , cos φ1 · sin φ2 − sin φ1 · cos φ2 · cos Δλ )

Here φ1 and λ1 are your latitude and longitude, φ2 and λ2 the Kaaba's, and Δλ = λ2 − λ1. West longitudes and south latitudes are negative. atan2 returns −180° to +180°, so the same page normalises the result to a compass bearing with (θ + 360) % 360.

atan2 rather than a plain arctangent matters. It looks at the signs of both arguments, so it can tell a bearing of 60° from one of 240°, which a ratio alone cannot.

Worked through for London

Take central London as 51.5074° N, 0.1278° W.

Δλ = 39.8262 − (−0.1278)                         = 39.9540°
 
y  = sin 39.9540° × cos 21.4225°
   = 0.6422 × 0.9309                             = 0.5978
 
x  = cos 51.5074° × sin 21.4225°
     − sin 51.5074° × cos 21.4225° × cos 39.9540°
   = 0.6224 × 0.3652 − 0.7827 × 0.9309 × 0.7666
   = 0.2273 − 0.5585                             = −0.3312
 
θ  = atan2(0.5978, −0.3312)                      = 118.99°

x is negative, which is the formula's way of saying the arc leaves London heading south of due east. Rounded, that is 119°, and on a 16-point compass it falls in the east-south-east sector (101.25° to 123.75°).

Three cities, checked twice

The formula above treats the Earth as a sphere. The Movable Type page notes that the Earth is "very slightly ellipsoidal" and that a spherical model "gives errors typically up to 0.3%". To check the hand calculation, and to see how much the sphere costs, the same three trips were run through Charles Karney's GeodSolve, which solves the problem on the WGS84 ellipsoid.

FromCoordinatesSphere (formula above)WGS84 ellipsoid (GeodSolve)Distance, ellipsoid
London51.5074° N, 0.1278° W118.99° (ESE)118.87°4,795 km
New York40.7128° N, 74.0060° W58.48° (ENE)58.40°10,324 km
Jakarta6.2088° S, 106.8456° E295.15° (WNW)295.02°7,922 km

The two methods agree to within 0.13° in all three cases. A tenth of a degree, across a prayer mat about a metre long, is a sideways shift of roughly 2 millimetres at the far edge. Either model is far more precise than any way of lining yourself up with it.

Why a Mac cannot point at it

A phone compass works by sensing the Earth's magnetic field. Apple's Core Location documentation, in Getting heading and course information, is direct about the hardware: "Heading information is available only on devices with a built-in magnetometer." The magnetometer "determines a device's orientation relative to magnetic north", and: "When location data is available, Core Location also reports the device's orientation relative to true north."

Apple does not list one for the Mac. Its iPhone 17 specifications list a "Digital compass" under Location. The MacBook Pro and MacBook Air specifications mention no compass or magnetometer. On the M4 Max MacBook Pro this post was written on, running macOS 27.0.1, CLLocationManager.headingAvailable() returns false. Check your own with two lines of Swift in Terminal:

printf 'import CoreLocation\nprint(CLLocationManager.headingAvailable())\n' > /tmp/h.swift
swift /tmp/h.swift

There is a second reason a desktop app should not try to fake magnetic north. A magnetic bearing is the true bearing minus the local magnetic declination, and declination varies by place and drifts over time. NOAA's declination calculator, using the WMM-2025 model on 3 October 2026, gives −12.46° for New York, +1.21° for London and +0.65° for Jakarta. In New York that is the difference between 58° and about 71° on a hand compass. The World Magnetic Model behind those figures is replaced every five years; NOAA says the current version "will remain valid until late 2029". Phones carry it. A Mac app would have to ship its own copy and keep it current, or ask a server.

What a Mac app can honestly show

That leaves a Mac app one honest output: the true bearing, a compass point to go with it, and a dial with north fixed at the top. A dial that spins would be animating a heading the machine does not have.

In PrayerTimes Pro the screen is called Qibla, reached from the More menu in the popover's footer. It draws a north-up dial over a dimmed map of your location, with a needle that swings to the bearing and settles. Under it are the bearing in whole degrees with its 16-point compass direction, your location, and one line: "Face this direction, measured clockwise from true north." The app's settings have a Qibla section with a "Measured From" choice. True north is selected, and Magnetic is shown greyed out, with the reason written beneath it: "A magnetic bearing needs a compass. No Mac has one, so the Qibla is measured from true north." A second switch, "Show Distance to Makkah", adds the great-circle distance in kilometres, or miles where the Mac's region uses them.

From the studio: PrayerTimes Pro works this bearing out on the Mac for wherever you are, shows it on a north-up dial with its compass point, and says plainly that it is measured from true north. The Qibla screen is part of the free app.

Why New York faces north-east

A flat world map says the opposite. On the familiar Mercator projection, Makkah sits well to the south of New York and a long way east, so a ruler laid between them points a little south of due east. That ruler line is a rhumb line: in Veness's words, "a path of constant bearing, which crosses all meridians at the same angle", and "rhumb lines are straight lines on a Mercator Projection map".

From New York, the rhumb line to the Kaaba has a bearing of 101.3° and a length of 10,965 km. The great circle starts out at 58.5° and is 10,306 km on the same sphere, so the rhumb line is 6.4% longer. The great circle leaves heading north-east, crosses the Atlantic in a long arc, and is heading 136°, south-east, by the time it reaches Makkah; GeodSolve gives the same arrival bearing, 136.04°. The flat map shows something like the end of the journey. The bearing you face is the start.

This was a live question for North American Muslims. The Qibla article records that in 1978 S. Kamal Abdali argued for a north-easterly Qibla using the great-circle method, that Riad Nachef and Samir Kadi argued for a south-easterly one in 1993, that Abdali replied in 1997 with an article called "The Correct Qibla", and that most North American Muslims came to accept the north-east, with a minority still facing south-east. Which direction is correct in religious terms is not a question this post answers. What it can say is which geometry each answer comes from.

The effect fades closer to Makkah. From London the two lines differ by about 15° (119.0° for the great circle, 133.8° for the rhumb line), and from Jakarta by about 2° (295.2° and 292.8°).

Turning a bearing into a direction in the room

The number is the easy half. The rest depends on finding true north where you are standing.

  • A phone compass. Core Location gives a phone a true-north heading whenever it has a location fix, so a phone compass reading true north can be held flat and turned until it shows the Mac's bearing.
  • The map. The Qibla dial in PrayerTimes Pro sits over a north-up map of your location. If you can see a street or a building on that map from your window, line the map up with it and the dial is lined up too.
  • The sun, twice a year. The Qibla article gives the moments the sun passes almost directly over the Kaaba: 27 and 28 May at about 09:18 UTC, and 15 and 16 July at about 09:27 UTC. At that moment, anywhere the sun is up, facing the sun is facing the Kaaba, and a vertical object's shadow lies along the Qibla line, pointing away from it.

How precisely you need to face it is a question for scholarship, not geometry. The same article reports that most Islamic scholars consider facing the general direction of the Kaaba (jihat al-ka'ba) acceptable when its exact direction (ayn al-ka'ba) cannot be determined; ask the scholars your community follows how that applies to you.

For the times themselves rather than the direction, the high-latitude Isha post explains why summer nights in the north push Isha so late. And if you want the bearing for your own Mac without doing the trigonometry, it is on the Qibla screen of PrayerTimes Pro, under More in its menu-bar popover.

All writingNextHow to remove vocals from a song (or keep them) without uploading it