Position.enableLocationEvents not calling the method

Hi all,

I have an App working well.

At the start, this App uses Position.enableLocationEvents to get the initial position of the device. This is working perfect.

Now, I am trying to add the possibilities for the users to acquire a new start position. I use the same methodology as before, but the methods onForcedPosition is simply never ever not called.

Any help is welcome... 

onUpdate()

if (ForceAcquisition==true) {

            Position.enableLocationEvents(Position.LOCATION_CONTINUOUS, method(:onForcedPosition));
            ForceAcquisition=false;}
function onForcedPosition(info) {
        System.println("PLEASE SHOW ME YOU WORk");
        InitialLoc = info.position.toRadians();
        Storage.setValue("PositionLat", InitialLoc[0]);
        Storage.setValue("PositionLon", InitialLoc[1]);
        Storage.setValue("DateDZAcquired", GPSFixDateString);
    }

Top Replies

  • I tried both Conti and one_shoot but nothing. The methods is simply not called, whatever the method. I also tried to move the Position.enableLocationEvents in different location, but nothing…

All Replies

  • You probably want to start GPS some place other than onUpdate(), like maybe initialize() as you don't want to call it more than once.

    Also, in the callback, you want to look at the accuracy as you may not be seeing a valid or current location.

  • Does your app need the position at any time other than startup and "forced acquisition"? If not, then try using Position.enableLocationEvents(Position.LOCATION_ONE_SHOT, ...) both times.

    If you actually need the location on a continuous basis, it seems like the 2nd call with LOCATION_CONTINUOUS won't work, as you found. In that case, just call enableLocationEvents once (at init time), and use a flag to determine what to do with the location.

    e.g. Something like:

    var forceStartAcquisition = true;
    var initialLocation = null;
    var currentLocation = null;
    
    // use a single callback to handle all position events
    function onPosition(info) {
      if (forceStartAcquisition) {
        initialLocation = info;
        forceStartAcquisition = false;
      }
      currentLocation = info;
      
      // do whatever ...
    }
    
    function initialize() {
      Position.enableLocationEvents(Position.LOCATION_CONTINUOUS, method(:onPosition));
      // ...
    }

  • Thanks for your help both. Some clarification...

    I get the initial position when users start the App. For that I use the ONE_SHOOT. Then, user can decide to start a record function, and here I use the CONTINUOUS. No issue here.

    Now, I am trying to provide the possibilities to get a updated initial position. I tried both Conti and one_shoot but nothing. The methods is simply not called, whatever the method. I also tried to move the Position.enableLocationEvents in different location, but nothing works.

  • Right, so why not leverage the existing callback with CONTINUOUS? Set a flag to say "I want to set a new start position", and do so in your CONTINUOUS callback.

  • "ONE_SHOT" doesn't do what you think on some devices.  You get an accuracy of "Last known", so not the current GPS.  I always do "Continuous" and then turn off GPS after a usable or good accuracy (you could also do "poor", but I don't)

    This is something you won't see in the sim but on a real device.

  • If you are recording a standard fit, when you do the session.start() for the first time, that will be your start location in Activity.Info.

  • If you are recording a standard fit, when you do the session.start() for the first time, that will be your start location in Activity.Info.

    If you read the original post, they're talking about setting a "start location" for the purposes of their app and saving it to storage (I assume they also have a way to display it in the app somehow); there was no mention of recording a FIT file. They also need the ability for the user to update the "start location" at will.

    I was simply responding in the context of the OP.

  • I tried both Conti and one_shoot but nothing. The methods is simply not called, whatever the method. I also tried to move the Position.enableLocationEvents in different location, but nothing works.

    Where else have you tried?  The initialize for the view?  Are you testing in the sim?  If so are you playing back a fit or simulating data to get GPS info?

    Simulation>Activity Data

  • I understand you both. I tried few things. One was to move the Position.enableLocationEvents of the update start position and depending where it is in the onupdate function it works. It looks something creates a porblem with the Position.enableLocationEvents, but no idea what it is... I need to sleep on it a bit. I will be back...

    I test with the sim and with a Fenix 5, same behavior.

    Again thank you both. 

  • No problem. I'm curious why you can't use the existing CONTINUOUS callback to set a new start location though?

    If the continuous callback is called fairly frequently, then it seems that callback could be used to set a new start location on demand, as in the example code I posted.

    Unless I'm missing something, I don't see why you need to register a new callback just to set a new start location.

    EDIT: I can think of 2 approaches which leverage the existing continuous callback:

    When the user wants to acquire a new start position...

    - ..set a flag so that the next position obtained by the continuous callback is used as the new start position

    - ...use the last position obtained by the continuous callback as the new start position