إضافة app.js - بسم الله الرحمن الرحيم
هذا الالتزام موجود في:
35
app.js
Normal file
35
app.js
Normal file
@@ -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);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
});
|
||||||
المرجع في مشكلة جديدة
حظر مستخدم