The geolocation plugin on Cordoba 5.0.0 always returns an error timeout

I installed Cordova 5.0.0 with these plugins:

cordova plugin list

cordova-plugin-device 1.0.1-dev "Device"
cordova-plugin-geolocation 1.0.0 "Geolocation"
cordova-plugin-globalization 1.0.0 "Globalization"
cordova-plugin-inappbrowser 1.0.1-dev "InAppBrowser"
cordova-plugin-network-information 1.0.0 "Network Information"
cordova-plugin-whitelist 1.0.1-dev "Whitelist"

Running this code on any Android virtual device:

onDeviceReady: function () {

    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');
    }
    var options = { maximumAge: 3000, timeout: 5000, enableHighAccuracy: true };
    navigator.geolocation.getCurrentPosition(onSuccess, onError, options);
}

Return:

D/CordovaNetworkManager( 1239): Connection Type: 3g
D/CordovaNetworkManager( 1239): Connection Extra Info: epc.tmobile.com
D/CordovaWebViewImpl( 1239): onPageFinished(file:///android_asset/www/index.html)
D/dalvikvm( 1239): GC_EXTERNAL_ALLOC freed 457K, 49% free 3174K/6151K, external 901K/1038K, paused 3ms
I/InputReader(  843): Device reconfigured: id=0x0, name=qwerty2, display size is now 240x400
I/InputManager-Callbacks(  843): No virtual keys found for device qwerty2.
D/SystemWebChromeClient( 1239): file:///android_asset/www/js/app.js: Line 127 : code: 3
D/SystemWebChromeClient( 1239): message: Timeout expired

Why does the timeout always expire?

+4
source share
4 answers

This may sound silly, but have you activated the GPS feature on your phone?

+8
source

, . : maximumAge timeout. / . , . GPS , . . -, . GPS , maximumAge ( ) , .

, , , , :

function gpsRetry(gpsOptions) {
    navigator.geolocation.getCurrentPosition(gpsSuccess, gpsError, gpsOptions);
}

:

function gpsError(error, gpsOptions) {
    alert('code: '    + error.code    + "\n" +
          'message: ' + error.message + "\n");
    gpsRetry(gpsOptions);

}

:

function gpsSuccess(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");
}

- onDeviceReady:

let gpsOptions = {maximumAge: 300000, timeout: 5000, enableHighAccuracy: true};
navigator.geolocation.getCurrentPosition(gpsSuccess, gpsError, gpsOptions);

, . , GPS- , ... , :

Send GPS coordinates for Android emulator

, , GPS.

+2

, , , :

.

, , .

+1

Samsung Tab S. , maximumAge timeOut watchOptions, :

var watchOptions = {
    enableHighAccuracy: true
};

var watch = $cordovaGeolocation.watchPosition(watchOptions);
+1

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


All Articles