GPS not firing up?

I need some help getting the GPS to fire up correctly. I have an application that runs a timer that gets GPS coordinates and sends them to a remote server for processing. I'm building exclusively for a Forerunner 945 LTE. 

My problem is everything works fine in the sim but as soon as i put it on a device I can't get any GPS data (I get 180deg for latitude and longitude, I assume because GPS is not turned on). I have followed the example here https://developer.garmin.com/connect-iq/api-docs/Toybox/Position.html (example with Timers).

So my function that runs in a timer looks like this.

var positionInfo = Position.getInfo();
if (positionInfo has :position == false || positionInfo.position == null) {
  return null;
}
var latLon = positionInfo.position.toDegrees();
var latitude = latLon[0];
var longitude = latLon[1];

...

I assume its because I need to first manually turn the GPS on. So I tried this instead.

private var _latitude
private var _longitude

onStart() {
Position.enableLocationEvents(Position.LOCATION_CONTINUOUS, method(:onPosition));
}

function onPosition(info) {
  var latLon = info.toDegrees();
  _latitude = latLon[0];
  _longitude = latLon[1];
}
...

But this also does not work. In my sim it never even runs the onPosition callback. Even when I manually change the position in the sim it doesn't run the callback. So I tried putting it on a device to see if it works there but it seems like it also never runs the callback. I've checked it by sending lat and long to my server and they are both null.

Any help would be greatly appreciated. This is my first Garmin app, so I'm rather new to the eco system.

Thanks!

Top Replies

All Replies

  • Try using this in the sim:

    Simulation>Activity Data and the just push the play button

  • This is a really stupid question, but are you sure onStart() is being called? I assume your code snippet is supposed to be from your class which is derived from AppBase, but if it isn't, then onStart() is not going to be called (unless you are calling it some other way)

    For example, if this is actually your View class, then providing an onStart() method won't do anything.

    You can at least verify that your code is being called in the sim by adding a System.println() statement after the call to Position.enableLocationEvents().

  • Yep, initially I had it in a separate class (in the constructor) but I have moved it to my AppBase just to make sure I'm not doing any fundamental mistake. I assume it doesn't matter where I put it as long as the code actually runs (which I verified for both cases). So my onStart in the example above is running fine. It's just the callback that doesn't.

  • Ah, I haven't seen that button until now, dark mode on mac + vs code sim.. black play button on black background Smiley Yes, this works and I get continuous calls to my onPosition function with coordinates. But how can I get this to happen on my device?

  • Is your onPosition() function not being called, or is it called and giving you bad info?

    When you do the enableLocationEvents() call your onPosition callback can be called a number of times before there is a GPS lock.  Typically, you'll start getting data in less than a minute, but it can be longer based on the last time GPS was used on the watch, how old your GPS prediction data is and your current environment - inside a building can take a long time.  Try using an activity like Run and see how long it takes for GPS to "go green".

    In the Position Info in your onPosition callback, check on the value in accuracy.  You have a minimal lock when it's QUALITY_POOR. Maybe display something in your app when you have usable GPS.

  • As far as I can tell the onPosition is not firing, or it is firing and giving me null values for my coordinates while on the device. I have only checked the logs from my server since I don't know how to debug on a device.

    So what I should do is enable the GPS in onStart and then wait until I have desired accuracy on the GPS before actually starting to send position data?

    I have tried going into run as you suggested and the GPS is red with a minimum bar, and it doesn't seem to change. Does it mean my device is having trouble establishing a good GPS signal?

  • Add System.println() calls to your apps  You then create a txt file apps/log .See https://forums.garmin.com/developer/connect-iq/w/wiki/4/new-developer-faq#debugging

    On your watch, go to about, and scoll down until you see CPE  or EPO.  It should say it's current.  That's the prediction data for GPS and expires in a short time.  If it's expired, it can take a long time to get a GPS lock.

  • Ah, thats great advice. Thanks. Will try to experiment some more and check my device logs and see whats going on there.

  • If you aren't getting a green GPS status with Run, you need to see what's going on with your wathc.  If it's got 5 buttons, press and hold thge upper left button for 15 seconds or so and the watch will turn itself off.  Then turn it back on.  This is a full reboot, but you first want to check CPE/EPO status in about.  If that's not current, try syncing with Garmin Express on a pc/mac to make sure you're up to date with the files. 

  • Checked the about section and it has Ephemeris set to current. Still getting a red gps bar on run. But I am inside and noticed that it improved slightly (still in the red) when I went to my balcony. Tried the reboot as you suggested and same results. It's a brand new watch so it should be working fine.