Let’s get your geolocation, super easy:
[pastacode lang=”javascript” message=”” highlight=”” provider=”manual”]
function getLocation(callback) {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(pos) {
var loc = {
lat: pos.coords.latitude,
long: pos.coords.longitude,
heading: pos.coords.heading
};
callback(loc);
});
}
}
[/pastacode]
You could use it like this:
[pastacode lang=”javascript” message=”” highlight=”” provider=”manual”]
getLocation(function(loc) {
console.log(loc)
});
[/pastacode]
One thought on “HTML5 Geolocation”