diff --git a/backend/endpoints/geo_access.py b/backend/endpoints/geo_access.py index a6cac48..8d304d0 100644 --- a/backend/endpoints/geo_access.py +++ b/backend/endpoints/geo_access.py @@ -31,3 +31,23 @@ async def get_geo_access(request: GeoAccessRequest): # "success": type_checker.get(request.type, "circle").is_inside(request.coords) # } return {"success": True} + +@geo_access_router.post("/real") +async def get_geo_access_real(request: GeoAccessRequest): + """Controllo reale se le coordinate sono dentro il raggio di 50 metri""" + try: + # Centro del controllo geografico (Lido di Bolzano) + CENTER_LAT = 46.68349 + CENTER_LON = 11.19043 + RADIUS_METERS = 50 + + # Creo il checker per il cerchio di 50 metri + from geo_access import CircleChecker + geo_checker = CircleChecker((CENTER_LAT, CENTER_LON), RADIUS_METERS) + + # Controllo se le coordinate sono dentro il cerchio + is_inside = geo_checker.is_inside(tuple(request.coords)) + + return {"success": is_inside} + except Exception as e: + return {"success": False, "error": str(e)} diff --git a/backend/geo_access.py b/backend/geo_access.py index eb19a12..2803b3a 100644 --- a/backend/geo_access.py +++ b/backend/geo_access.py @@ -1,5 +1,4 @@ from math import radians, sin, cos, sqrt, atan2 -from shapely import Polygon # class PolygonChecker: diff --git a/testing/index.html b/testing/index.html index 5c37f3c..d5dc0f2 100644 --- a/testing/index.html +++ b/testing/index.html @@ -58,6 +58,20 @@ .btn-coordinates:hover { background-color: #F57C00; } + .btn-gps { + background-color: #9C27B0; + color: white; + } + .btn-gps:hover { + background-color: #7B1FA2; + } + .btn-molinella { + background-color: #795548; + color: white; + } + .btn-molinella:hover { + background-color: #5D4037; + } .result { background-color: #f9f9f9; border: 1px solid #ddd; @@ -94,6 +108,8 @@ + +
diff --git a/testing/script.js b/testing/script.js index 0b2f3f3..9cddcd5 100644 --- a/testing/script.js +++ b/testing/script.js @@ -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 {