Created
December 4, 2011 14:14
-
-
Save freretuc/1430293 to your computer and use it in GitHub Desktop.
geolocalisation javascript
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
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 + "&size=300x300&maptype=roadmap&zoom=16&key=GOOLE-API-KEY | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment