Location Object in Data Field?

Former Member
Former Member
I´m owner of a Edge 520 and pretty new to coding Connect IQ.
Is about to create a custom set of Data Fields and just want to get confirmation, Is it impossible to use a Location Object for Data Fields?
Using currentLocation, Altitude and similar only gives a permission error.

Thanks in advance!
  • When compute() is called in a data field, it is passed Activity.info, and the data you're looking for is available there. No need to get it elsewhere.
  • Former Member
    Former Member over 9 years ago
    When compute() is called in a data field, it is passed Activity.info, and the data you're looking for is available there. No need to get it elsewhere.


    I may have missunderstood but this is called right?:
    http://developer.garmin.com/downloads/connect-iq/monkey-c/doc/Toybox/Activity/Info.html

    But if I use info.currentLocation I get a Permission Error since I cant tick The "Positioning" box in my Project Settings.
    And everything isn´t available in activity.info either, I wanna calculate Slope but for that I need my current altitude and thats not (what I know about) available through activity.info.
  • But if I use info.currentLocation I get a Permission Error since I cant tick The "Positioning" box in my Project Settings.


    No. Did you try it? It works just fine for me in a data field, and has worked this way for as long as I can remember. This code..

    function compute(info) {
    if (info.currentLocation != null) {
    Sys.println("Location: " + info.currentLocation.toDegrees());
    }
    else {
    Sys.println("Location: null");
    }

    if (info.altitude != null) {
    Sys.println("Altitude: " + info.altitude);
    }
    else {
    Sys.println("Altitude: null");
    }
    }


    ... prints this (I click Simulation > FIT Data > Simulate Data after about 3 seconds of simulating)

    Shell Version 0.1.0
    Location: null
    Altitude: null
    Location: null
    Altitude: null
    Location: null
    Altitude: null
    Location: [38.895996, -94.760896]
    Altitude: 3173.993408
    Location: [38.895977, -94.760885]
    Altitude: 3173.694824
    Location: [38.895885, -94.760857]
    Altitude: 3174.198730
    Complete


    And everything isn´t available in activity.info either, I wanna calculate Slope but for that I need my current altitude and thats not (what I know about) available through activity.info.

    Again, no. You didn't look at the documentation very carefully. The Activity.Info object has a member named altitude, and you can access it as I've shown above. Additionally, if you want to access the Activity.Info outside of the compute() method, you can call Activity.getActivityInfo().

    Travis
  • Travis is 100% correct. I use the same basic logic in a few different DF's, (all the stuff you're looking for).

    But I'll add a footnote!

    You'll notice how in his code he always does a "null check" before using something. In the simulator, you likely won't need that if you have simulated data running, but on a real device, you really do need it, as during startup, some things may not yet have a value. For example, when you fire up an app, there won't be a "start location" until the recording actually starts.
  • Yes. You should test in the simulator when no data is being simulated as well as with simulated data.
  • Former Member
    Former Member over 9 years ago
    No. Did you try it? It works just fine for me in a data field, and has worked this way for as long as I can remember. This code..

    function compute(info) {
    if (info.currentLocation != null) {
    Sys.println("Location: " + info.currentLocation.toDegrees());
    }
    else {
    Sys.println("Location: null");
    }

    if (info.altitude != null) {
    Sys.println("Altitude: " + info.altitude);
    }
    else {
    Sys.println("Altitude: null");
    }
    }


    ... prints this (I click Simulation > FIT Data > Simulate Data after about 3 seconds of simulating)

    Shell Version 0.1.0
    Location: null
    Altitude: null
    Location: null
    Altitude: null
    Location: null
    Altitude: null
    Location: [38.895996, -94.760896]
    Altitude: 3173.993408
    Location: [38.895977, -94.760885]
    Altitude: 3173.694824
    Location: [38.895885, -94.760857]
    Altitude: 3174.198730
    Complete



    Again, no. You didn't look at the documentation very carefully. The Activity.Info object has a member named altitude, and you can access it as I've shown above. Additionally, if you want to access the Activity.Info outside of the compute() method, you can call Activity.getActivityInfo().

    Travis

    Thanks Guys! (I said I was a beginner right? :p)
    Weird, I really got a Permission error yesterday, but Copy Paste your code worked like a charm :confused:
    However I started using the code from the PositionSample that came with the SDK, and that isn´t using the activity.info right?

    Same about the altitude, was looking for something called "currentAltitude" or similar, missed the obvious there :(


    I always use the "Null" check for the activity.info and got my Data Field working fine on the Emulator, both with and without Simulation activated.
    However when I try it on my Device, I see the field for a second or so and then it´s replaced by an IQ-logo with a Yellow Exclamation mark, and I assume it says that the DF crashed.
    Is it possible to debug in some ways when it runs on my device?
  • I started using the code from the PositionSample that came with the SDK...

    The PositionSample is a watch-app. It gets position data using an entirely different method (it registers for position updates). The method it uses requires the Position permission.


    ... I see the field for a second or so and then it´s replaced by an IQ-logo with a Yellow Exclamation mark, and I assume it says that the DF crashed.

    Yes, it crashed.

    Is it possible to debug in some ways when it runs on my device?

    The best thing you can get right now is the printf debugger. Item 6 in the New Developer FAQ covers how to do that.
  • Former Member
    Former Member over 9 years ago
    Thanks for your responses!
    I´ll take a llook in the Log-folder and see what causes the crash.
  • When sideloading with "Build for Device", don't click the box for "Build Release Version", as you'll get more info in ciq_log.txt if you don't.
  • Former Member
    Former Member over 9 years ago
    Thanks,

    Just got my Data Field running on my device as well, it seems that you can´t have to much null-checks...
    Adding it for a couple of more places used for calculations fixed my errors.