Overview
The Qibla utilities provide functions to calculate the direction to Mecca (Kaaba) from any geographical location. This is essential for determining the prayer direction for Muslims worldwide.calculateQiblaBearing
Calculates the Qibla bearing (direction to Mecca) from a given latitude and longitude using the great-circle distance formula.Parameters
The latitude of the location in degrees. Valid range: -90 to 90.
The longitude of the location in degrees. Valid range: -180 to 180.
Returns
The Qibla bearing in degrees (0-360), where:
- 0° = North
- 90° = East
- 180° = South
- 270° = West
Example
Reference Coordinates
The Qibla calculation uses the following coordinates for the Kaaba in Mecca:- Latitude: 21.422487°N
- Longitude: 39.826206°E
Algorithm
The function uses the spherical law of cosines to calculate the bearing:- Converts input coordinates from degrees to radians
- Calculates the difference in longitude
- Applies the bearing formula:
atan2(sin(Δlon) × cos(lat2), cos(lat1) × sin(lat2) - sin(lat1) × cos(lat2) × cos(Δlon)) - Converts the result back to degrees and normalizes to 0-360° range