Under Review
over 1 year ago

WERETECH-13396

Position.enableLocations documentation has a bug in code example (causes device to crash)

(See: https://forums.garmin.com/developer/connect-iq/f/discussion/319709/enable-location-bug-after-24-10-update)

The documentation at the following URL has a bug which causes a crash:

[https://developer.garmin.com/connect-iq/api-docs/Toybox/Position.html#enableLocationEvents-instance_function]

Original code:

if (Position has :CONFIGURATION_GPS_GLONASS_GALILEO_BEIDOU_L1_L5) {
    options[:configuration] = :CONFIGURATION_GPS_GLONASS_GALILEO_BEIDOU_L1_L5;

Correct code:

if (Position has :CONFIGURATION_GPS_GLONASS_GALILEO_BEIDOU_L1_L5) {
    options[:configuration] = Position.CONFIGURATION_GPS_GLONASS_GALILEO_BEIDOU_L1_L5;


Parents
  • Furthermore, the documented example still fails after the suggested correction because there's no check for hasConfigurationSupport().

    A more comprehensive fix would look like this:

    //...
    if (
      Position has :CONFIGURATION_GPS_GLONASS_GALILEO_BEIDOU_L1_L5 &&
      Position has :hasConfigurationSupport &&
      Position.hasConfigurationSupport(Position.CONFIGURATION_GPS_GLONASS_GALILEO_BEIDOU_L1_L5)
    ) {
        options[:configuration] = Position.CONFIGURATION_GPS_GLONASS_GALILEO_BEIDOU_L1_L5;
    }
    //...

Comment
  • Furthermore, the documented example still fails after the suggested correction because there's no check for hasConfigurationSupport().

    A more comprehensive fix would look like this:

    //...
    if (
      Position has :CONFIGURATION_GPS_GLONASS_GALILEO_BEIDOU_L1_L5 &&
      Position has :hasConfigurationSupport &&
      Position.hasConfigurationSupport(Position.CONFIGURATION_GPS_GLONASS_GALILEO_BEIDOU_L1_L5)
    ) {
        options[:configuration] = Position.CONFIGURATION_GPS_GLONASS_GALILEO_BEIDOU_L1_L5;
    }
    //...

Children
No Data