From f8dbb4cf2b20907b6fb3986387f2965669fda4aa Mon Sep 17 00:00:00 2001 From: layla_fullstack Date: Wed, 5 Aug 2026 09:58:48 +0000 Subject: [PATCH] =?UTF-8?q?=D8=A5=D8=B6=D8=A7=D9=81=D8=A9=20app.js=20-=20?= =?UTF-8?q?=D8=A8=D8=B3=D9=85=20=D8=A7=D9=84=D9=84=D9=87=20=D8=A7=D9=84?= =?UTF-8?q?=D8=B1=D8=AD=D9=85=D9=86=20=D8=A7=D9=84=D8=B1=D8=AD=D9=8A=D9=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 app.js diff --git a/app.js b/app.js new file mode 100644 index 0000000..ca11278 --- /dev/null +++ b/app.js @@ -0,0 +1,35 @@ +// Qibla Finder - محدد القبلة +const KAABA = { lat: 21.4225, lng: 39.8262 }; + +function toRad(deg) { return deg * Math.PI / 180; } +function toDeg(rad) { return rad * 180 / Math.PI; } + +function getQiblaBearing(lat, lng) { + const latR = toRad(lat), lngR = toRad(lng); + const kLatR = toRad(KAABA.lat), kLngR = toRad(KAABA.lng); + const deltaLng = kLngR - lngR; + const y = Math.sin(deltaLng) * Math.cos(kLatR); + const x = Math.cos(latR) * Math.sin(kLatR) - Math.sin(latR) * Math.cos(kLatR) * Math.cos(deltaLng); + return (toDeg(Math.atan2(y, x)) + 360) % 360; +} + +document.getElementById('locateBtn').addEventListener('click', () => { + if (!navigator.geolocation) { + alert('متصفحك لا يدعم تحديد الموقع'); + return; + } + document.getElementById('bearing').textContent = 'جاري التحديد...'; + navigator.geolocation.getCurrentPosition( + (pos) => { + const { latitude, longitude } = pos.coords; + const bearing = getQiblaBearing(latitude, longitude); + document.getElementById('bearing').textContent = `${bearing.toFixed(1)}°`; + document.getElementById('coords').textContent = `خط العرض: ${latitude.toFixed(4)} | خط الطول: ${longitude.toFixed(4)}`; + document.getElementById('needle').style.transform = `translate(-50%, -100%) rotate(${bearing}deg)`; + }, + (err) => { + document.getElementById('bearing').textContent = 'فشل تحديد الموقع'; + console.error(err); + } + ); +});