Created
September 24, 2013 18:33
-
-
Save codeguy/6689215 to your computer and use it in GitHub Desktop.
Get user's current gelocation with HTML Geolocation API
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
if ('geolocation' in navigator) { | |
console.log('Supports HTML geolocation API'); | |
(function () { | |
var onSuccess = function (location) { | |
console.log('User location', location); | |
var userLat = location.coords.latitude, | |
userLon = location .coords.longitude; | |
}, | |
onError = function (code, message) { | |
console.log('Gelocation error', code, message); | |
}; | |
navigator.geolocation.getCurrentPosition(onSuccess, onError); | |
})(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment