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.20
JST 0.034
BTC 99331.95
ETH 3298.98
USDT 1.00
SBD 3.05