Your IP : 216.73.216.65


Current Path : /home/ataenra/www/ATA/INTRANET/Formulaires/SOL_PV/
Upload File :
Current File : /home/ataenra/www/ATA/INTRANET/Formulaires/SOL_PV/PV.php

<!DOCTYPE html>
<html lang="fr">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Google Maps Géolocalisation</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        body {
            font-family: Arial, sans-serif;
            background-color: #f1f5f9;
            min-height: 100vh;
            padding: 1rem;
        }

        .container {
            max-width: 1200px;
            margin: 0 auto;
        }

        .card {
            background: white;
            border-radius: 0.5rem;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
            overflow: hidden;
        }

        .header {
            background: #2563eb;
            color: white;
            padding: 1rem;
        }

        .header h1 {
            font-size: 1.5rem;
            display: flex;
            align-items: center;
            gap: 0.5rem;
        }

        .error-message {
            margin-top: 0.5rem;
            background: #1d4ed8;
            padding: 0.5rem;
            border-radius: 0.25rem;
            font-size: 0.875rem;
        }

        .content {
            padding: 1rem;
            display: grid;
            grid-template-columns: 2fr 1fr;
            gap: 1rem;
        }

        #map {
            height: 500px;
            border-radius: 0.5rem;
            overflow: hidden;
        }

        .coordinates {
            background: #f8fafc;
            padding: 1rem;
            border-radius: 0.5rem;
        }

        .coordinates h2 {
            font-size: 1.25rem;
            margin-bottom: 1rem;
            color: #1e293b;
        }

        .coordinate-box {
            background: white;
            padding: 0.75rem;
            border-radius: 0.375rem;
            margin-bottom: 0.5rem;
            box-shadow: 0 1px 2px rgba(0, 0, 0, 0.05);
        }

        .coordinate-box p:first-child {
            color: #64748b;
            font-size: 0.875rem;
            margin-bottom: 0.25rem;
        }

        .coordinate-box p:last-child {
            font-family: monospace;
            font-size: 1.125rem;
        }

        @media (max-width: 768px) {
            .content {
                grid-template-columns: 1fr;
            }
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="card">
            
            
            <div class="content">
                <div id="map"></div>
                <div class="coordinates">
                    <h2>Coordonnées du marqueur</h2>
                    <div id="coordinates-display">
                        <div class="coordinate-box">
                            <p>Latitude</p>
                            <p id="lat">-</p>
                            <p>Latitude a stocker</p>
                            <p id="lat1">-</p>

                        </div>
                        <div class="coordinate-box">
                            <p>Longitude</p>
                            <p id="lng">-</p>
                            <p>Longitude a stocker</p>
                            <p id="lng1">-</p>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script>
        const DEFAULT_LOCATION = { lat: 51, lng: 2 };
        let map, marker;

        function initMap() {
            // Fonction pour mettre à jour l'affichage des coordonnées
            function updateCoordinates(position) {
                document.getElementById('lat').textContent = position.lat.toFixed(6);
                document.getElementById('lng').textContent = position.lng.toFixed(6);
                document.getElementById('lat1').textContent = position.lat.toFixed(6);
                document.getElementById('lng1').textContent = position.lng.toFixed(6);
            }

            // Fonction pour initialiser la carte avec une position
            function createMap(position) {
                map = new google.maps.Map(document.getElementById('map'), {
                    center: position,
                    zoom: 15,
                    styles: [{
                        featureType: "poi",
                        elementType: "labels",
                        stylers: [{ visibility: "off" }]
                    }]
                });

                // Créer le marqueur
                marker = new google.maps.Marker({
                    position: position,
                    map: map,
                    animation: google.maps.Animation.DROP
                });

                // Mettre à jour les coordonnées initiales
                updateCoordinates(position);

                // Ajouter l'écouteur de clic sur la carte
                map.addListener('click', (e) => {
                    const position = {
                        lat: e.latLng.lat(),
                        lng: e.latLng.lng()
                        
                    };
                    marker.setPosition(position);
                    updateCoordinates(position);
                });
            }

            // Tenter d'obtenir la position de l'utilisateur
            if (navigator.geolocation) {
                navigator.geolocation.getCurrentPosition(
                    (position) => {
                        const userLocation = {
                            lat: position.coords.latitude,
                            lng: position.coords.longitude
                        };
                        createMap(userLocation);
                    },
                    (error) => {
                        console.error('Erreur de géolocalisation:', error);
                        const errorContainer = document.getElementById('error-container');
                        errorContainer.innerHTML = `
                            <div class="error-message">
                                Permission de géolocalisation refusée - Utilisation de la position par défaut (51°N, 2°E)
                            </div>
                        `;
                        createMap(DEFAULT_LOCATION);
                    },
                    {
                        timeout: 5000,
                        enableHighAccuracy: true
                    }
                );
            } else {
                console.error('La géolocalisation n\'est pas supportée');
                createMap(DEFAULT_LOCATION);
            }
        }
    </script>
    <script async defer src="https://maps.googleapis.com/maps/api/js?key=AIzaSyBJK0GVBASHQUIFbE3NudYEWFtodD9bM_s&callback=initMap"></script>
</body>
</html>