HTML and CSS Reference
In-Depth Information
Esempio 8.14 - Visualizzare la posizione del client su una mappa, usando Geolocation
API.
function initPage()
{
if (!Modernizr.geolocation)
{
alert("Il client non supporta la geolocalizzazione");
return;
}
// ottengo la posizione del visitatore:
navigator.geolocation.getCurrentPosition(showMap,
function (error) { alert(error.message); },
{ enableHighAccuracy: true, timeout: 10000, maximumAge: 0
});
};
function showMap(position)
{
// visualizzo le informazioni sulla posizione:
document.getElementById("debug").innerHTML =
"<p>latitude: " + position.coords.latitude + "<br>\n" +
"longitude: " + position.coords.longitude + "<br>\n" +
"accuracy: " + position.coords.accuracy + " metri</p>";
// creo una mappa con Google Maps centrata sulla posizio-
ne:
var location = new goo-
gle.maps.LatLng(position.coords.latitude,
position.coords.longitude);
var map = new goo-
gle.maps.Map(document.getElementById("map"), {
zoom: 12, mapTypeId: google.maps.MapTypeId.ROADMAP, cen-
ter:
location
});
 
Search WWH ::




Custom Search