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.26
TRX 0.11
JST 0.033
BTC 64961.60
ETH 3103.64
USDT 1.00
SBD 3.86