Can you explain this code into more easier chunks for me please

Here is the code

document.addEventListener(“deviceready”, loaded, false);

        var watchID = null;
         
        function loaded() {
            watchID = navigator.geolocation.watchPosition(success, error);
            alert("loaded");
        }
         
         
        function success(position) {
            var element = document.getElementById('geolocation');
            element.innerHTML = 'Latitude: ' + position.coords.latitude     + '<br />' +
            'Longitude: '           + position.coords.longitude             + '<br />' +
            'Altitude: '            + position.coords.altitude              + '<br />' +
            'Timestamp: '           + new Date(position.timestamp)          + '<br />' +
            '<hr>' + element.innerHTML;
        }
   

         
        function error(error) {
            alert(error.message);
        }
    function clearWatch() {
    if (watchID != null) {
        navigator.geolocation.clearWatch(watchID);
        watchID = null;
            }
        }
// wait for event "deviceready" and execute function 'loaded'
    document.addEventListener("deviceready", loaded, false);

// initialize variable
    var watchID = null;

// watch for position changes and on every change call function 'success' (gets called with 'position')
// set watchID so the watching could be stopped
// if some kind of error, call function 'error' (gets called with 'error')
      function loaded() {
          watchID = navigator.geolocation.watchPosition(success, error);
          alert("loaded");
      }

// position changed
      function success(position) {
// output  HTML
          var element = document.getElementById('geolocation');
          element.innerHTML = 'Latitude: ' + position.coords.latitude     + '<br />' +
          'Longitude: '           + position.coords.longitude             + '<br />' +
          'Altitude: '            + position.coords.altitude              + '<br />' +
          'Timestamp: '           + new Date(position.timestamp)          + '<br />' +
          '<hr>' + element.innerHTML;
      }
       
// some kind of error during geolocation
      function error(error) {
          alert(error.message);
      }
      
// clear 'watchID' to stop watching geolocation changes
      function clearWatch() {
        if (watchID != null) {
          navigator.geolocation.clearWatch(watchID);
          watchID = null;
        }
      }
1 Like

Many many thanks indeed