I'm trying to make an application that uses the HTML5 Geolocation feature after scanning a QR code. I want to make this purely a web application and avoid having to build an android application.

Only problem is, once I scan my QR code, the javascript doesn't work. Here is my code:



function setGeolocation() {
    var geolocation = window.navigator.geolocation.watchPosition(
        function ( position ) {
            latitude = position.coords.latitude;
            longitude = position.coords.longitude;
            accuracy = position.coords.accuracy;
            sendData(latitude, longitude);
        }
    );
};



    function sendData(latitude, longitude){
    $.ajax({
       url: 'map_data.php',
       data: {'latitude':latitude, 'longitude':longitude},
       type: 'POST',
       success: function(data){
          $('.show').html('<b>'+data+'</b>');
          window.location='load.php';
       }
    });
    }


The function at the bottom is called with a Button. It's not an issue of the function not being called.

Is there a way to change/fix this in the code, or is it something more major? Any help would be appreciated, thank you