HTML5 Geolocation

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

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.