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