Last active
December 11, 2015 07:48
-
-
Save rdmurphy/4568351 to your computer and use it in GitHub Desktop.
How I use HTML5 geolocation in my apps.
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
<span class="geoFind" id="geoFind">Just find me!</span> |
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
$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