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

@ -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)}

View file

@ -1,5 +1,4 @@
from math import radians, sin, cos, sqrt, atan2
from shapely import Polygon
# class PolygonChecker:

View file

@ -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 @@
<button class="btn-get" onclick="getData()">📥 GET Data</button>
<button class="btn-post" onclick="createData()">📤 POST Data</button>
<button class="btn-coordinates" onclick="createCoordinates()">📍 POST Coordinates</button>
<button class="btn-gps" onclick="checkGPSLocation()">🌍 Check GPS Location</button>
<button class="btn-molinella" onclick="sendMolinellaCoordinates()">🏘️ Send Molinella coordinates</button>
</div>
<div id="status"></div>

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 {