JSFiddle - React, Tailwind, and code Playground

by ahomu

HTML

<button id="js-geoloc">getCurrentPosition</button>
<p id="js-latlng"></p>

CSS

#js-geoloc {
    font-size: 150%;
    padding: 20px;
}

JavaScript

$(function() {
    var $latlng = $('#js-latlng');

    $('#js-geoloc').bind('touchend', function() {
        $latlng.text('location updating....');
        navigator.geolocation.getCurrentPosition(
            onSuccess, onError, {maximumAge: 600000, timeout: 30}
        );
    });

    function onSuccess(pos) {
        $latlng.text(pos.coords.latitude + ' : ' +pos.coords.longitude);
    }
    
    function onError() {
        alert('error');
    }

});