Created
October 5, 2011 15:01
-
-
Save raykrueger/1264645 to your computer and use it in GitHub Desktop.
Geolocation example
This file contains hidden or 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
$(document).ready(function() { | |
if (!!navigator.geolocation) { | |
navigator.geolocation.getCurrentPosition( | |
function(position) { | |
var lat = position.coords.latitude | |
var lng = position.coords.longitude | |
$.get('/locate' + '?lat=' + lat + '&lng=' + lng, function(data){ | |
$('#locations').html(data); | |
$('.stripey li:even').addClass('alt'); | |
}); | |
}, | |
function(e){ | |
$('#locations').html('<p>' + "Sorry, there was an error getting your current location" + '</p>'); | |
} | |
); | |
} else { | |
var message = "I'm sorry, but geolocation services are not supported by your browser."; | |
$('#locations').html('<p>' + message + '</p>'); | |
alert(message); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment