Skip to content

Instantly share code, notes, and snippets.

@raykrueger
Created October 5, 2011 15:01
Show Gist options
  • Save raykrueger/1264645 to your computer and use it in GitHub Desktop.
Save raykrueger/1264645 to your computer and use it in GitHub Desktop.
Geolocation example
$(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