Navigator.geolocation.getCurrentPosition stopped working

I am developing a phonegap application focused on the iOS platform. I want to capture the geographic location of the user. I use below code for this, which worked fine for a while and suddenly stopped working

    <script type="text/javascript">

    var onSuccess = function(position) {
        alert('Latitude: '          + position.coords.latitude          + '\n' +
              'Longitude: '         + position.coords.longitude         + '\n' +
              'Altitude: '          + position.coords.altitude          + '\n' +
              'Accuracy: '          + position.coords.accuracy          + '\n' +
              'Altitude Accuracy: ' + position.coords.altitudeAccuracy  + '\n' +
              'Heading: '           + position.coords.heading           + '\n' +
              'Speed: '             + position.coords.speed             + '\n' +
              'Timestamp: '         + position.timestamp                + '\n');
    };

    // onError Callback receives a PositionError object
    //
    function onError(error) {
        alert('code: '    + error.code    + '\n' +
              'message: ' + error.message + '\n');
     }

    navigator.geolocation.getCurrentPosition(onSuccess, onError);

    </script>

Above, the code returned latitude and longitude by about 7 times, but after that the callback function is not called, and sometimes it shows that the user has disabled the pop-up in the browser.

+4
source share
1 answer

You can try the following options:

{timeout: 30000, enableHighAccuracy: true, maximumAge: 75000}

//navigator.geolocation.getCurrentPosition(successCallback, errorCallback, {timeout: 30000, enableHighAccuracy: true, maximumAge: 75000});

enableHighAccuracy - (/), , ( )

maximumAge - ( ) ( , / )

timeout - ( ), Geo

0

Source: https://habr.com/ru/post/1535734/


All Articles