Qibla Direction
Precise compass bearing to the Kaaba in Makkah using spherical trigonometry. Returns direction name, bearing in degrees, and distance in km and miles.
Calculate Qibla Direction
GET/api/v1/qibla
Returns the Qibla direction (compass bearing to the Kaaba) from any location on Earth.
Query Parameters
| Parameter | Type | Description |
|---|---|---|
| lat* | float | Latitude of the location. Range: -90 to 90 |
| lon* | float | Longitude of the location. Range: -180 to 180 |
| api_key* | string | Your API key. Can also be sent via X-API-Key header. |
Try Qibla API
Try Qibla API
Use your API key to send a live Qibla request from documentation.
Latitude in decimal degrees.
Longitude in decimal degrees.
Used as the
api_key query parameter.GET /api/v1/qibla?lat=LATITUDE&lon=LONGITUDE&api_key=YOUR_KEYExample Request
bash
curl "https://your-domain.com/api/v1/qibla?lat=24.7136&lon=46.6753&api_key=YOUR_KEY"javascript
const response = await fetch(
'https://your-domain.com/api/v1/qibla?lat=24.7136&lon=46.6753',
{ headers: { 'X-API-Key': 'YOUR_KEY' } }
);
const data = await response.json();
console.log(data);python
import requests
response = requests.get(
'https://your-domain.com/api/v1/qibla',
params={'lat': 24.7136, 'lon': 46.6753},
headers={'X-API-Key': 'YOUR_KEY'}
)
print(response.json())Example Response
json
{
"success": true,
"service": "qibla-direction",
"data": {
"qibla_direction": "Northwest",
"compass_bearing": 295.4,
"location": {
"latitude": 24.7136,
"longitude": 46.6753
},
"kaaba_coordinates": {
"latitude": 21.4225,
"longitude": 39.8262
},
"distance_km": 865.2,
"distance_miles": 537.6,
"note": "Face Northwest to pray towards the Kaaba."
},
"timestamp": "2026-05-10T10:00:00.000Z",
"api_info": {
"usage": "GET /api/v1/qibla?lat=LATITUDE&lon=LONGITUDE&api_key=YOUR_KEY"
}
}Response Fields
| Field | Type | Description |
|---|---|---|
success | boolean | true when the request succeeded |
service | string | Service identifier — always "qibla-direction" |
data.qibla_direction | string | Cardinal/intercardinal direction (e.g. "Northwest") |
data.compass_bearing | number | Bearing in degrees from North (0–360) |
data.location | object | Input latitude and longitude |
data.kaaba_coordinates | object | Fixed coordinates of the Kaaba |
data.distance_km | number | Great-circle distance to Kaaba in kilometres |
data.distance_miles | number | Great-circle distance to Kaaba in miles |
data.note | string | Human-readable facing instruction |
timestamp | string | ISO 8601 response timestamp |
api_info.usage | string | Endpoint usage template |
Error Responses
Missing or invalid coordinates — 400 Bad Request
json
{
"success": false,
"error": "Bad Request",
"message": "lat and lon are required and must be valid numbers."
}Invalid API key — 401 Unauthorized
json
{
"success": false,
"error": "Unauthorized",
"message": "Invalid or missing API key."
}Compass Direction Reference
| Bearing Range | Direction |
|---|---|
| 337.5° – 360° / 0° – 22.5° | North |
| 22.5° – 67.5° | Northeast |
| 67.5° – 112.5° | East |
| 112.5° – 157.5° | Southeast |
| 157.5° – 202.5° | South |
| 202.5° – 247.5° | Southwest |
| 247.5° – 292.5° | West |
| 292.5° – 337.5° | Northwest ← most common for Middle East users |