You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@cordova.apache.org by "Placido Curro (JIRA)" <ji...@apache.org> on 2017/01/18 08:40:26 UTC

[jira] [Comment Edited] (CB-12308) Unable to get gps position

    [ https://issues.apache.org/jira/browse/CB-12308?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15827624#comment-15827624 ] 

Placido Curro edited comment on CB-12308 at 1/18/17 8:40 AM:
-------------------------------------------------------------

Hello,
I have created a basic cordova project with the android platform.

The config xml file has just the minimal settings, including two plugins for the geolocation.

1) name="cordova-plugin-geolocation" spec="~2.4.1"
2)  name="cordova-plugin-mauron85-background-geolocation" spec="~2.2.5"

Then, I have just a function that tries to get the current gps position.

function gps(  ) {

  var gGpsAccuracy = false;
  var gGeoTimeout = 30 * 1000;
  var gMaximumAge = 60 * 1000;

  console.warn( new Date() )
    var onSuccess = function(position){ console.warn( new Date().toString(),position) };
    var onError =   function(error){ console.error(new Date().toString(), error)};

    navigator.geolocation.getCurrentPosition(
      function(position)
        {
            alert('ok ' + JSON.stringify(position));
            onSuccess(position);
      },
      function(error)
      {
        alert('error ' + JSON.stringify(error))
        onError( error);
      }, {'enableHighAccuracy': gGpsAccuracy, 'timeout':gGeoTimeout,'maximumAge':gMaximumAge});
}

in the ondeviceready callback, I call gps() or you can add a button in the html to call gps().

If you want to try the other plugin you can do this way:

    var callbackFn = function(location) {
         console.log('[js] BackgroundGeolocation callback:  ' + location.latitude + ',' + location.longitude);
         backgroundGeolocation.finish();
     };

     var failureFn = function(error) {
         console.log('BackgroundGeolocation error');
     };

     // BackgroundGeolocation is highly configurable. See platform specific configuration options
     backgroundGeolocation.configure(callbackFn, failureFn, {
         desiredAccuracy: 10,
         stationaryRadius: 20,
         distanceFilter: 30,
         interval: 60000
     });

     // Turn ON the background-geolocation system.  The user will be tracked whenever they suspend the app.
     backgroundGeolocation.start();

I have attached the files that let you  have the same situation. Thanks for you help and your attention.
Regards,
plco.




was (Author: plco):
Hello,
I have created a basic cordova project with the android platform.

The config xml file has just the minimal settings, including two plugins for the geolocation.

1) name="cordova-plugin-geolocation" spec="~2.4.1"
2)  name="cordova-plugin-mauron85-background-geolocation" spec="~2.2.5"

Then, I have just a function that tries to get the current gps position.

function gps(  ) {

  var gGpsAccuracy = false;
  var gGeoTimeout = 30 * 1000;
  var gMaximumAge = 60 * 1000;

  console.warn( new Date() )
    var onSuccess = function(position){ console.warn( new Date().toString(),position) };
    var onError =   function(error){ console.error(new Date().toString(), error)};

    navigator.geolocation.getCurrentPosition(
      function(position)
        {
            alert('ok ' + JSON.stringify(position));
            onSuccess(position);
      },
      function(error)
      {
        alert('error ' + JSON.stringify(error))
        onError( error);
      }, {'enableHighAccuracy': gGpsAccuracy, 'timeout':gGeoTimeout,'maximumAge':gMaximumAge});
}

in the ondeviceready callback, I call gps() or you can add a button in the html to call gps().

If you want to try the other plugin you can do this way:

    var callbackFn = function(location) {
         console.log('[js] BackgroundGeolocation callback:  ' + location.latitude + ',' + location.longitude);
         backgroundGeolocation.finish();
     };

     var failureFn = function(error) {
         console.log('BackgroundGeolocation error');
     };

     // BackgroundGeolocation is highly configurable. See platform specific configuration options
     backgroundGeolocation.configure(callbackFn, failureFn, {
         desiredAccuracy: 10,
         stationaryRadius: 20,
         distanceFilter: 30,
         interval: 60000
     });

     // Turn ON the background-geolocation system.  The user will be tracked whenever they suspend the app.
     backgroundGeolocation.start();

Thanks for you help and your attention.
Regards,
plco.



> Unable to get gps position
> --------------------------
>
>                 Key: CB-12308
>                 URL: https://issues.apache.org/jira/browse/CB-12308
>             Project: Apache Cordova
>          Issue Type: Bug
>          Components: Plugin Geolocation
>    Affects Versions: 6.4.0
>         Environment: Android 5.1
>            Reporter: Placido Curro
>         Attachments: www.zip
>
>
> Hello,
> on my Android mobile phone, a Meizu M3s Android 5.1, gps plugin doesn't work very well.
> I have developed a basic app with just the gps plugin and a button to get the current gps position. I run it, and when I push the button to get current position, I get the 'on error' callback with timeout error.
> Of course, the app has access to gps and global gps setting is on.
> If I turn the mobile off and on, then the app works and I get the position. But, if I put the mobile in stand-by and I leave it for a while (10 minutes for example), then the app stops working and and gps requests expire per timeout.
> Enableaccuracy, timeout and age options doesn't affect the bug. I experience the same problem, even if a try to reduce or to increase timeout and age, or set EnableAccuracy true or false.
> Thanks for your attention.
> Regards, plco.
> P.S. Later, I have added the cordova-plugin-mauron85-background-geolocation plugin and while the cordova gps plugin still expires per timeout, this one manages to get the current gps position.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@cordova.apache.org
For additional commands, e-mail: issues-help@cordova.apache.org