1446
Views
5
Comments
Solved
[Location Plugin]     navigator.geolocation.getCurrentPosition(onSuccess, onError) - undefined
Question
location-plugin
Mobile icon
Forge asset by OutSystems

Hi,

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


2018-05-10 22-41-57
Carlos Filipe Simões
Staff
Solution

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

2021-05-05 13-05-18
Mykola (Nick) Tkachenko

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 https://www.outsystems.com/forums/discussion/21261/getlocation-always-has-error-timeout-expired-on-android/ can be marked as solved :)



2018-05-10 22-41-57
Carlos Filipe Simões
Staff

Cool! Out of curiosity, was it app permissions?

2021-05-05 13-05-18
Mykola (Nick) Tkachenko

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.

2018-05-10 22-41-57
Carlos Filipe Simões
Staff

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

Best regards,

Carlos Simões

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.