I need to capture the user's location and compare all the sites listed in a list / array and see which one is closest and show an image of the location. So far I have been able to handle errors and find where the user is. Anyone have any idea how I can proceed?
Below is what I've done:
<html>
<body>
<p id="demo"></p>
</body>
</html>
<script>
var x=document.getElementById("demo");
function getLocation()
{
if (navigator.geolocation)
{
navigator.geolocation.getCurrentPosition(showPosition,showError);
}
else{x.innerHTML="Seu browser não suporta Geolocalização.";}
}
function showPosition(position)
{
x.innerHTML="Latitude: " + position.coords.latitude +
"<br>Longitude: " + position.coords.longitude;
}
function showError(error)
{
switch(error.code)
{
case error.PERMISSION_DENIED:
x.innerHTML="User reject."
break;
case error.POSITION_UNAVAILABLE:
x.innerHTML="Location unavaliable."
break;
case error.TIMEOUT:
x.innerHTML="timeout."
break;
case error.UNKNOWN_ERROR:
x.innerHTML="Error."
break;
}
}
</script>
Aucun commentaire:
Enregistrer un commentaire