Help creating waypoints

If I'm correct, when recording an activity, it's possible to create a waypoint in the current activity file. I'm hoping this waypoint will appear in the activity file that I can download from Garmin Connect as a gpx file.
Is this right? If so....

It seems to be using persisted Content which is all pretty obscure to me from the programmers guide.
Could someone give me a leg up on this please?
I have a session:
$.session = Record.createSession({ :name => "raceQs racing", :sport => Record.SPORT_GENERIC });
$.session.start();
When my user presses a button, I would like to record the current location as a waypoint with a specific name.

I have the current location object.

Could you show me the code for this please?
Many thanks
  • If I'm correct, when recording an activity, it's possible to create a waypoint in the current activity file.


    No, this is not possible. You could add a lap via addLap(), but you wouldn't be able to store a name for that lap marker and you wouldn't be able to download the coordinate of the waypoint later from Garmin Connect.

    It seems to be using persisted Content which is all pretty obscure to me from the programmers guide.


    What is so obscure about this? The saveWaypoint method takes two parameters, the location of the coordinate and a map that contains a single entry for the name of that waypoint.

    using Toybox.PersistedContent;
    
    class XDelegate extends Ui.BehaviorDelegate
    {
        hidden var _M_count;
        hidden var _M_info;
    
        function initialize() {
            _M_count = 0;
        }
    
        function onSelect() {
    
            if (_M_info == null || _M_info.accuracy < Position.QUALITY_POOR) {
                return false;
            }
    
            if (!PersistedContent has :saveWaypoint) {
                return false;
            }
    
            ++_M_count;
    
            var options = {
                :name => Lang.format("Point $1$", [ _M_count ]);
            };
    
            PersistedContent.saveWaypoint(_M_info.position, options);
    
            return true;
        }
    
        // someone would register this class for position events
        function onPosition(info) {
            _M_info = info;
        }
    }
    


    Travis

  • As Travis mentioned, I use addLap() to mark one in the .fit file. When you view it in GC, you can see the lap marks on the map, and when looking at lap/splits, you can see the time/distance etc between the marks, and from GC can export it to google maps, and get location etc. I use the same key used for manual laps in other apps to mark one (the back button)

    I do my own "save waypoints" in the app's Object Store. When the app starts, you can select to load the saved ones or not. I did this before PresistedContent was available, and it works on devices that don't have it today. There's never a confusion about what the waypoint is used for (when you call "getWaypoint()" is it one of interest to the app?).

    I don't name the WP's, but they are numbered, and when I display the chart of the route in the app, you can toggle between showing a symbol or a number for each one, and on another screen I have a table by number for the distance and direction to each waypoint. (entering text can be a pain on the device itself, and with numbers, it needs less space on the other screens)
  • Thanks guys, again:)
    I guess it's obscure, because I'm looking for a feature that doesn't exist!
    I have used your advice to create a waypoint, but I still don't understand where the waypoint I created actually exists. I'm still coming to grips with CIQ to review my activity, and I can't see the waypoint there.
    So I don't understand what is the use case for waypoints, if they don't show up in the activity.

    My use case is to record the position of the two ends of the race start line so I can review (post race) my boat's actual position at the time of the start - late (need to improve) , on time (great) or over early (disaster) .
  • Some of it could be that with waypoints, you got to consider other devices (like an Oregon for example), where other things can be involved like Basecamp.

    When you do an addLap() it is in the .fit that gets uploaded to Garmin Connect, and when you view the activity in GC or GCM and look at laps/splits you see them.
  • So that pretty much confirms that waypoints are not a feature I can use in my app which is targeted for VA-HR.
    Laps really don't sound promising for my application either.
    I really do have the need to be able to record position data for later analysis, but I can't work out from reading the manuals the best way to proceed.
    Coming from a GPS and GPX/KML background, I think in terms of waypoints with attributes of name, time, lat/lon/alt, speed and heading.
    It seems to me that I might be able to record position data using the FIT Developer fields, and then use Connect SDK to extract them for analysis, but my reading of FIT Developer fields would tend to indicate it only supports single-attribute records.
    Any thoughts?
  • Former Member
    Former Member
    Lap messages in the file do contain position. (They contain the position of the start and end of the lap. The end position is the location the lap was created.) As best I can tell, they do not contain altitude or speed. Fit Contributor fields are intended to only contain a single type of data, but you can add more than one to single entry in the file, so you could add these things with the FIT Contributor. You could also add a name to the lap message in the file. It would be possible to process the file and convert these to the waypoint format you are looking for.
  • Hm, still far away from home, so I am not able to check a code now, but as I understand it, something like the following code should work:

    CODE

    Is this correct? And how would it be possible to get the coordinates (lat/lon), the altitude or even a symbol id for the saved waypoints?
  • Your code gives a run-time error
    Failed invoking <symbol>Symbol Not Found Error
    on the line
    PersistedContent.saveWaypoint.... (Unable to post code...gets error!)
    I would like to get it working, so your input would be appreciated. I tried to examine the location variable with
    Sys.println("New Position: lat,"+location[:latitude] );
    But also got Failed invoking <symbol>Symbol Not Found Error
    What do the <> symbols mean in the doco:
    var location = new Position.Location( { :latitude => <latitude_coordinates>, :longitude => <longitude_coordinates>, :format => :degrees } );
  • Hopefully I'll be able to do some coding next monday - actually I only can guess...

    * have you included all libraries (using Toybox.Position as Pos, using Toybox.System as Sys etc.)?
    * do you have all permissions set? BTW I believe, 'position' isn't available for datafields
    * the <coordinates> just indicate the meaning of the (floating point) values at this place

    * to do an output, something like var m=info.currentLocation.toDegrees; Sys.println(m[0]+m[1]); should work (info is seen in datafield's compute event)...
    * in widgets, something like x=Pos.getInfo(); y=x.position; may do the same like y=info.currentLocation; as seen above.
    * not sure if these things work - and no idea how to get the coordinate information from waypoints...
  • Your code for examining the object doesn't work, because latitude is not a member of Location.
    Sys.println("New Position: lat,"+location[:latitude] ); //won't work


    The SDK explains how you use one of three functions to get coordinates out of a Location:
    toDegrees &#8658; Toybox::Lang::Array
    Get a Location object's coordinates in degrees.

    toGeoString(format)&#8658; Toybox::Lang::String
    Get a String representation a Location object's coordinates.

    toRadians &#8658; Toybox::Lang::Array
    Get a location object's coordinates in radians.


    The code you want to use instead is:

    (substitute the equals sign for EQUALS below)
    var locationDegrees EQUALS location.toDegrees();
    Sys.println("New Position: lat,"+locationDegrees[0]);
    Sys.println("New Position: long,"+locationDegrees[1]);



    It won't be interesting output, because you'll only get the original lat and long back, as expected. (I can't type the numbers into this post, here.)

    Note that the SDK says saveWaypoint() is supported as follows:
    Since:
    • 2.2.0

    Supported Devices:
    • All devices execept Approach S60
    • vivoactive
    • vivoactive HR


    And PersistedContent as a whole is a 2.2 feature.

    So check the SDK/device you are targeting in the simulator. And make sure you have the correct Using statements, like Puffolino said.
    using Toybox.PersistedContent; using Toybox.Position;

    no idea how to get the coordinate information from waypoints...


    I don't think you can get coordinates from waypoints. I think the point of PersistedContent is to launch the associated apps:
    https://developer.garmin.com/connect...stedcontent2.2