Simple JS/jQuery Geolocation Example

in js •  8 years ago 

Create new HTML document
Add two tags with classes .pos-latitude-value and .pos-longitude-value
Add jQuery (tested on 1.9)

js code:

(function($) {
    var k = 0;
    function showPosition(position) {
        $('.pos-latitude-value').html(position.coords.latitude);
        $('.pos-longitude-value').html(position.coords.longitude);
        k++;
        console.log('Checked ' + k + ' times');
        $('.status').html('Checked ' + k + ' times');
    }

    function getPosition(){
        navigator.geolocation.getCurrentPosition(showPosition);
    }
    getPosition();
    setInterval(getPosition, 1000);
})(jQuery);
Authors get paid when people like you upvote their post.
If you enjoyed what you read here, create your account today and start earning FREE STEEM!