[Location Plugin]  navigator.geolocation.getCurrentPosition(onSuccess, onError) - undefined

Forge Component
Published on 3 Apr by OutSystems R&D
21 votes
Published on 3 Apr by OutSystems R&D


On Android I always have undefined as a result of calling example through console:

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);

Is it a bug in plugin or something I can fix on my side?

Thank you


Hello, Mykola,

Hmm, there were two things I couldn't understand:

  1. What exactly evaluates as 'undefined' ? The whole 'position' variable? Have you checked location permissions for your app?
  2. Which example did you get this code from, exactly?

Best regards,

Carlos Simões


Hi Carlos,

Example is from git page https://github.com/OutSystems/cordova-plugin-geolocation.git

Meanwhile I found the source of the problem in my device settings. So this issue and this http://www.outsystems.com/forums/discussion/21261/getlocation-always-has-error-timeout-expired-on-android/ can be marked as solved :)

Cool! Out of curiosity, was it app permissions?

Not only. App permission I had to disable/enable few times and restart the device (can be just my device problem). Also the was problem in my UI flow so when device started get gps info it didn't refresh the "no gps" message properly.

Ok, thanks! Feel free to ask if there's anything else you need to clear up!

Best regards,

Carlos Simões