1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
| function callbackSuccess(position) {
var posInfo = "Votre position a été déterminée avec succès ! <br />";
posInfo += "Latitude : " + position.coords.latitude + "<br />";
posInfo += "Longitude : " + position.coords.longitude + "<br />";
posInfo += "Altitude : " + position.coords.altitude + "<br />";
document.getElementById('position').innerHTML = posInfo;
var latlng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
var gmapsOptions = {
mapTypeControl: false,
center: latlng,
navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
mapTypeId: google.maps.MapTypeId.ROADMAP,
zoom: 10
};
var map = new google.maps.Map(document.getElementById('map'), gmapsOptions);
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: "Vous êtes ici",
icon:"images/pin.png"
});
}
function callbackError(error) {
var info = "Erreur lors de la géolocalisation : ";
switch (error.code) {
case error.TIMEOUT:
info += "La durée de traitement est trop importante !";
break;
case error.PERMISSION_DENIED:
info += "Vous n'avez pas donné la permission !";
break;
case error.POSITION_UNAVAILABLE:
info += "La position n'a pu être déterminée !";
break;
case error.UNKNOWN_ERROR:
info += "Une erreur inconnue a eu lieu !";
break;
}
document.getElementById('position').innerHTML = info;
}
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(callbackSuccess, callbackError, {enableHighAccuracy: true, timeout: 960000, maximumAge: 120000});
} else {
alert("L'API de géolocalisation n'est pas disponible, il faudrait proposer une alternative !");
} |
Partager