Help wanted: instanceof Location fails

Hmm....

Can anybody tell me why the following Simple Data Field fails in the instanceof statement?

using Toybox.WatchUi as Ui;
using Toybox.System as Sys;
using Toybox.Position as Pos;

class TestInstanceOfLocationView extends Ui.SimpleDataField {

function initialize() {
label = "My Label";
}

function compute(info) {
var current = info.currentLocation;

Sys.println("> "+current instanceof Pos.Location);
return 0.0;
}
}


I'm reasonable sure that the info is an Activity.Info object and current is a Position.Location object... So why does this fail with the following lines?

...
Device Version 0.32.4Device id 0 name "A garmin device"
Shell Version 458227Permission required
Permission Required
@PC = 0x10000036
Failed invoking <symbol>
Permission Required
Permission Required
Permission Required


The PC refers to the instanceof statement :-)
  • Former Member
    Former Member over 10 years ago
    For using the Position module a users permission is required. If you ad that permission for a data field I suspect you'll get another error, because that module is not avaiable for a data field. See page 31 of the programmers guide.
  • Former Member
    Former Member over 10 years ago
    You can use the object and it's atributes and methods, but you can't initialize or reference the class.

    It's the same with info.currentLocationAccuracy. This gives a value of type number, that's equal to a constant in the Position module. You can use it, but you can't compare it to the constant, because you can't get to that.
  • You can use the object and it's atributes and methods, but you can't initialize or reference the class.


    Initialize: ok; reference: hmm, not ok

    It's the same with info.currentLocationAccuracy. This gives a value of type number, that's equal to a constant in the Position module. You can use it, but you can't compare it to the constant, because you can't get to that.


    Exactly and likewise, you can't call "current.toGeoString(Pos.GEO_DMS)"! :-(

    Please do something about this Connect IQ Team!

    The reason why I want to test the type in the first place, is because I get an OOM error when I call toRadians in the simulator:

    Failed invoking <symbol>
    Out Of Memory Error
    @PC = 0x300007e8
    @PC = 0x1000032e
    Out Of Memory Error
    Out Of Memory Error


    0x300007e8 corresponds to Positioning.mb line 93 which is part of the toRadians...

    Very mystified!
  • Former Member
    Former Member over 10 years ago
    Could the out of memory error be related to the fact that toRadians returns an Array with 2 values of type Double. It's a known bug that a Double takes about 280 bytes of memory. I think an Array takes another 27 bytes and 1 byte overhead per item, so that's about 589 bytes for one location in radians (out of 5500 you have available for your datafield..
  • Ohh...

    Where do these numbers come from? I must have missed it some how :-(

    It completely explains all me observations: if I delete small sections of the code for the data field - even a method that are never called - or if I remove a file with debug methods that isn't used, then it works. Otherwise it does not..

    Aghh... Just adding

    var startLL = start.toRadians();
    startLL = [startLL[0].toFloat(), startLL[1].toFloat()];


    solved most of the problems... And I can do even better...

    Thanks so much!!!
  • I believe the original discussion about the exorbitant size of Double and the sizes of various types comes form this thread.