-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3af90d
commit ef572ef
Showing
1 changed file
with
30 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,41 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script> | ||
<script src="https://cdn.rawgit.com/jeromeetienne/ar.js/2.0.0/aframe/build/aframe-ar.js"></script> | ||
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes"> | ||
</head> | ||
<body style="margin: 0; overflow: hidden;"> | ||
<a-scene embedded arjs="sourceType: webcam;"> | ||
<a-entity gps-entity-place></a-entity> | ||
<a-camera gps-camera="simulateAltitude: false;"></a-camera> | ||
</a-scene> | ||
<body> | ||
<h1>Verifica posizione GPS</h1> | ||
<button onclick="getLocation()">Mostra la mia posizione</button> | ||
|
||
<script> | ||
// Mostra un alert con la posizione dell'utente | ||
const camera = document.querySelector('a-camera'); | ||
camera.addEventListener('gps-camera-update-position', function (event) { | ||
console.log("Evento rilevato:", event); | ||
const { latitude, longitude } = event.detail.position; | ||
alert(`La tua posizione è:\nLatitudine: ${latitude}\nLongitudine: ${longitude}`); | ||
}); | ||
function getLocation() { | ||
if (navigator.geolocation) { | ||
navigator.geolocation.getCurrentPosition(showPosition, showError); | ||
} else { | ||
alert("La geolocalizzazione non è supportata da questo browser."); | ||
} | ||
} | ||
|
||
camera.addEventListener('gps-camera-error', function (error) { | ||
console.error("Errore GPS:", error); | ||
}); | ||
function showPosition(position) { | ||
alert(`Latitudine: ${position.coords.latitude}, Longitudine: ${position.coords.longitude}`); | ||
} | ||
|
||
function showError(error) { | ||
switch(error.code) { | ||
case error.PERMISSION_DENIED: | ||
alert("Utente ha negato la richiesta di geolocalizzazione."); | ||
break; | ||
case error.POSITION_UNAVAILABLE: | ||
alert("Informazioni sulla posizione non disponibili."); | ||
break; | ||
case error.TIMEOUT: | ||
alert("La richiesta di localizzazione è scaduta."); | ||
break; | ||
case error.UNKNOWN_ERROR: | ||
alert("Errore sconosciuto."); | ||
break; | ||
} | ||
} | ||
</script> | ||
</body> | ||
</html> |