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 = '