Skip to content

Instantly share code, notes, and snippets.

@rdmurphy
Last active December 11, 2015 07:48
Show Gist options
  • Save rdmurphy/4568351 to your computer and use it in GitHub Desktop.
Save rdmurphy/4568351 to your computer and use it in GitHub Desktop.
How I use HTML5 geolocation in my apps.
<span class="geoFind" id="geoFind">Just find me!</span>
$geoFind = $('#geoFind');
if (!navigator.geolocation) {
$geoFind.hide();
} else {
$geoFind.on('click', function() {
navigator.geolocation.getCurrentPosition( function(position) {
var lat = position.coords.latitude; // use these as you please!
var lng = position.coords.longitude; // use these as you please!
}, function(error) {
alert('There was a problem! Please try using the search box instead.');
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment