File size: 3,762 Bytes
c53ebb0
ed6c4f4
 
c53ebb0
 
ed6c4f4
c53ebb0
 
 
 
 
 
 
 
 
ed6c4f4
 
 
c53ebb0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ed6c4f4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91

document.addEventListener('DOMContentLoaded', function() {
    const findQiblaBtn = document.getElementById('find-qibla');
    const openMapBtn = document.getElementById('open-map');
    const useCameraBtn = document.getElementById('use-camera');
    const resultDiv = document.getElementById('result');
    let map;

    // Initialize Google Maps
    function initMap() {
        map = new google.maps.Map(document.getElementById('map-container'), {
            center: {lat: 0, lng: 0},
            zoom: 8
        });
    }
    findQiblaBtn.addEventListener('click', function() {
        simulateQiblaFinding();
    });

    openMapBtn.addEventListener('click', function() {
        if (navigator.geolocation) {
            navigator.geolocation.getCurrentPosition(
                (position) => {
                    const pos = {
                        lat: position.coords.latitude,
                        lng: position.coords.longitude
                    };
                    
                    // Center map on user's location
                    map.setCenter(pos);
                    new google.maps.Marker({
                        position: pos,
                        map: map,
                        title: "Your Location"
                    });
                    
                    resultDiv.classList.remove('hidden');
                },
                () => {
                    alert('Error: The Geolocation service failed or your browser doesn\'t support geolocation.');
                }
            );
        } else {
            alert("Error: Your browser doesn't support geolocation.");
        }
    });

    useCameraBtn.addEventListener('click', function() {
        if (navigator.mediaDevices && navigator.mediaDevices.getUserMedia) {
            navigator.mediaDevices.getUserMedia({ video: true })
                .then(function(stream) {
                    const video = document.createElement('video');
                    video.srcObject = stream;
                    video.play();
                    
                    const cameraContainer = document.createElement('div');
                    cameraContainer.className = 'mt-6 rounded-lg overflow-hidden h-64 w-full bg-black flex items-center justify-center';
                    cameraContainer.innerHTML = '<div class="absolute w-full h-full flex items-center justify-center"><div class="qibla-arrow"></div></div>';
                    cameraContainer.appendChild(video);
                    
                    resultDiv.innerHTML = '';
                    resultDiv.appendChild(cameraContainer);
                    resultDiv.classList.remove('hidden');
                })
                .catch(function(error) {
                    alert("Error accessing camera: " + error.message);
                });
        } else {
            alert("Error: Camera access not supported in your browser.");
        }
    });
function simulateQiblaFinding() {
        findQiblaBtn.disabled = true;
        findQiblaBtn.innerHTML = '<i data-feather="loader" class="animate-spin mr-2"></i> Locating...';
        feather.replace();
        
        setTimeout(() => {
            // Simulate API call delay
            const randomDirection = Math.floor(Math.random() * 360);
            document.getElementById('qibla-direction').textContent = randomDirection + '°';
            
            findQiblaBtn.innerHTML = '<i data-feather="compass" class="mr-2"></i> Find Qibla Direction';
            findQiblaBtn.disabled = false;
            resultDiv.classList.remove('hidden');
            feather.replace();
            
            // In a real implementation, load Google Maps here
            // with the calculated Qibla direction
        }, 2000);
    }
});