GPS stops continuously reading after 10 seconds

Hello,

I have been working on an app which shows the compass heading while a user is moving.  I've used this code:-

Position.enableLocationEvents(Position.LOCATION_CONTINUOUS, method(:onPosition));

to ensure that the user is constantly informed of the direction they are taking.  It works well in the simulator (although it fluctuates wildly but at least it's constantly working on the position) but when I try it out on an actual device (vivoactive 4S) after I've set the GPS it works for a little while, then will settle on a particular location and not move, even when the user changes direction.  Is there something else I need to do, either on code or in the device settings?

Thanks in advance.

  • How are you getting the compass reading?  How fast are you moving?  Under a certain speed, the actual compass is used, and after that, with GPS, it's the direction you are moving and not the way the devices is facing.

  • Hi Jim,

    I'm using the lat and lon from Position.getInfo().position inside a TimerCallback function which runs every second, then using a trig formula to work out the direction by comparing the last two coordinates. I have been testing it while riding on a bus (no car :-o ) so therefore I'm happy with getting the direction I am moving.  I hope this helps.

  • Why not just use Sensor.getInfo().heading?

    There's also Activity.getActivityInfo().currentHeading, but you may need to have a session started for that one.

    Are you sure lat/lon aren't changing, or that the bus isn't impacting GPS reception?

  • Yes, I've got all three as possibilities for the heading, but never really sure which one is the best.  I have seen threads on this forum that show the Position one is the best (and would not need an activity session to work).  For all of them, I'm getting negative readings when I use them as below, which is why I opted for the position:-

    var info = Sensor.getInfo();
    var pInfo = Position.getInfo();
    var aInfo = Activity.getActivityInfo();
    mHeading = Math.toDegrees(info.heading);
    pHeading = Math.toDegrees(pInfo.heading);
    aHeading = Math.toDegrees(aInfo.currentHeading);

  • Understand that north is 0.  from there things will be from -180 to +180 when you look at it in degrees.

  • I can get a GPS reading on a moving bus after a few seconds, as opposed to inside when I don't get any reading at all (which is expected).

    The process I use is that I open the app first (which is set to reset to 0 upon start).  At this point I have not set the GPS so nothing moves.  Then while in the app I long-press the top button and to to the GPS option.  After a few seconds the location details will appear, and fluctuates a bit while trying to set a location.  Now, if at this point I immediately leave the GPS which takes me to my app, the heading briefly gets around where I expect (so if I'm going eastwards it would read around 80-90) but then it stops moving before it gets a true reading; and will stay that way even if the bus changes direction.

    If I wait in the GPS area until it settles before going to the app, nothing happens when I go to the app (because it didn't get a chance to get two sets of lat/lon before working out the heading).

  • OK.  So how can I get it to show from 0 to 360 degrees?  Because it won't look right to see minus something degrees...

  • With GPS, you want to watch the accuracy in Position.Info and ignore lat/lon if the accuracy is bad.

    Yes, 80 to 90 would be you are heading east.  -80 to -90, your heading is west.

  • var deg=info.heading*(180.0/Math.PI); //convert to degrees

    if(deg<0) {deg=(360.0+deg);} //handle -180 to 0

    Try myABC: https://apps.garmin.com/en-US/apps/fdecbeaf-7d99-45e4-80e5-b5f9c2e92365

    Shows the heading without GPS being involved.

  • So if I understand what you're saying, would the best approach be to use the lat/lon (Position.getInfo().position) if the accuracy is good, but switch to the heading (Position.getInfo().heading) if the accuracy is bad?