HTML5 Geolocation

Let’s get your geolocation, super easy:

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);
        });
    }
} 

You could use it like this:

getLocation(function(loc) {
    console.log(loc)
});

 

One thought on “HTML5 Geolocation

Leave a Reply

Your email address will not be published. Required fields are marked *