Skip to content

Instantly share code, notes, and snippets.

@freretuc
Created December 4, 2011 14:14
Show Gist options
  • Save freretuc/1430293 to your computer and use it in GitHub Desktop.
Save freretuc/1430293 to your computer and use it in GitHub Desktop.
geolocalisation javascript
if (!navigator.geolocation) {
// geolocalisation non disponible pour le navigateur...
alert("#failed : geolocalisation not aviable with your browser. Sorry.");
} else {
// on tente de geolocaliser la personne...
navigator.geolocation.getCurrentPosition(whereiam);
}
function whereiam(position) {
// données utiles :
// position.coords.latitude
// position.coords.longitude
// position.coords.accuracy (exactitude, possiblement en mètres)
// un alert par exemple
alert('Vous êtes proche de la position ' + position.coords.latitude + '° lat, ' + position.coords.longitude + '° lon');
// on peut utiliser une google map aussi dans une balise <img alt="" />
// http://maps.google.com/staticmap?center=" + position.coords.latitude + "," + position.coords.longitude + "&amp;size=300x300&amp;maptype=roadmap&amp;zoom=16&amp;key=GOOLE-API-KEY
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment