add first version real geo-access

This commit is contained in:
Alessio Prato 2025-08-02 02:57:45 +02:00
parent 45c7e94096
commit 2f32706bda
4 changed files with 135 additions and 1 deletions

View file

@ -93,6 +93,105 @@ async function createCoordinates() {
}
}
// Check GPS Location
async function checkGPSLocation() {
try {
console.log('🌍 Richiesta coordinate GPS...');
showStatus('🌍 Richiesta coordinate GPS...', true);
// Ottieni coordinate GPS
const position = await getCurrentPosition();
const { latitude, longitude } = position.coords;
console.log(`📍 Coordinate GPS: ${latitude}, ${longitude}`);
showStatus(`📍 Coordinate GPS ottenute: ${latitude.toFixed(6)}, ${longitude.toFixed(6)}`, true);
// Chiama la route geo-access/real
const coordinates = {
"coords": [latitude, longitude]
};
const response = await fetch(`${API_BASE_URL}/geo-access/real`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(coordinates)
});
const data = await response.json();
if (response.ok) {
const result = data.success ? '✅ DENTRO' : '❌ FUORI';
showStatus(`${result} - Sei ${data.success ? 'dentro' : 'fuori'} dal raggio di 50 metri!`, data.success);
showResult(data);
} else {
showStatus(`❌ Errore: ${data.detail || 'Errore sconosciuto'}`, false);
}
} catch (error) {
console.error('Errore GPS:', error);
showStatus(`❌ Errore GPS: ${error.message}`, false);
}
}
// Funzione per ottenere la posizione GPS
function getCurrentPosition() {
return new Promise((resolve, reject) => {
if (!navigator.geolocation) {
reject(new Error('Geolocalizzazione non supportata'));
return;
}
navigator.geolocation.getCurrentPosition(
(position) => resolve(position),
(error) => reject(new Error(`Errore GPS: ${error.message}`)),
{
enableHighAccuracy: true,
timeout: 10000,
maximumAge: 60000
}
);
});
}
// Send Molinella coordinates
async function sendMolinellaCoordinates() {
try {
console.log('🏘️ Invio coordinate Molinella...');
showStatus('🏘️ Invio coordinate Molinella...', true);
// Coordinate hardcoded di Molinella
const coordinates = {
"coords": [44.61758, 11.66719]
};
console.log(`📍 Coordinate Molinella: ${coordinates.coords[0]}, ${coordinates.coords[1]}`);
showStatus(`📍 Coordinate Molinella: ${coordinates.coords[0]}, ${coordinates.coords[1]}`, true);
// Chiama la route geo-access/real
const response = await fetch(`${API_BASE_URL}/geo-access/real`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(coordinates)
});
const data = await response.json();
if (response.ok) {
const result = data.success ? '✅ DENTRO' : '❌ FUORI';
showStatus(`${result} - Molinella è ${data.success ? 'dentro' : 'fuori'} dal raggio di 50 metri!`, data.success);
showResult(data);
} else {
showStatus(`❌ Errore: ${data.detail || 'Errore sconosciuto'}`, false);
}
} catch (error) {
console.error('Errore Molinella:', error);
showStatus(`❌ Errore di connessione: ${error.message}`, false);
}
}
// Test di connessione all'avvio
window.addEventListener('load', async () => {
try {