Tuesday, 24 March 2015

geolocation-api

// http://jonrohan.me/guide/javascript/geolocation-api/
function getLocation() {
2 if(navigator.geolocation) {
3 navigator.geolocation.getCurrentPosition(foundLocation, noLocation);
4 } else {
5 noLocation();
6 }
7 }
8 function foundLocation(position) {
9 var lat = position.coords.latitude;
10 var long = position.coords.longitude;
11 $("#current-location").replaceWith('<a id="current-location" href="http://maps.google.com/?q=' + lat + ',' + long + '" target="_blank">' + lat + ', ' + long + '</a>');
12 }
13 function noLocation() {
14 $("#current-location").text('Could not find location');
15 }
16 $("#get-location").click(getLocation);
view raw gistfile1.js hosted with ❤ by GitHub

No comments:

Post a Comment