| Current Path : /home/ataenra/www/ATA/INTRANET/Formulaires/SOL_PV/ |
| Current File : /home/ataenra/www/ATA/INTRANET/Formulaires/SOL_PV/maps.js |
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);
}
// 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);
}
}