Simple JS/jQuery Geolocation Example

in #js8 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);

Coin Marketplace

STEEM 0.21
TRX 0.25
JST 0.039
BTC 95276.42
ETH 3297.99
USDT 1.00
SBD 3.16