How to display/draw the track you've covered in my own app?

Former Member
Former Member
Fenix 3 native running app has a functionality (a face) where it drwas out the route I've covered. I'd like to add same functionality to my own app. Basically implement the same view into my own app:


Any ideas on how to do it in an efficient way? Just saving tones of GPS coordinates and showing them as dots doesn't seem to be the nicest way. Also scaling of the drawing is an interesting challenge since ideally it should "zoom in" according to the distance covered.

Or has someone done it and is maybe ready to share some sample code?
  • I've done it in a few things. I have a DF, a walking app, and two hiking apps that can do it (see Chart DF, Simple Walk, Hike, and Hike2 in my app store link)

    But no code to share - A function here and there wouldn't make much sense without the full app, and there are two parts of this - collecting the data and displaying that data. I'll explain the basics of how I do it.

    You need to be in something that does GPS (app, DF), have a bunch of memory to use as an array and the code to do that, and code to display that data (the two parts).

    first the array and collecting data:
    You want to save the lat/lon on a regular basis (every 30 sec,min,2 min, etc). For the array, you want one to be as easy on memory and objects as possible as you want to save as much as possible (there are other threads here about how to do that), and when you save things, you want to use a simple object (such as a float vs a double). And you need to figure out what to do if you run out of room in the array. (how you handle this is probably the real tricky part here)

    Now the display
    So let's say you have 1000 lat/lon pairs. First thing, is you really don't want to use all 1000, as on the screen, that would be kind of excess and likely trigger the watchdog timer. Decide how many make sense (100-200 maybe?) Let's use 100. So if you have 100 pairs, display them all, with 200, every other one, with 300, every 3rd one, etc.

    Then look at the 100 you'll be using, and track their min/max lat and lon. This will let you know how to scale the display (assuming no pan/zoom). Then using that scaling (ranges of lat and lon), calculate the screen x and y for each of the 100 and draw them.

    This whole thing is a bit tricky, and there are probably some "got ya's" I forgot, but those are the basics of how I do it. (oh, one is how you figure out how many lat/long pairs to save. I base that on the device and how much memory is still available in the app)
  • At the next level of detail, to save memory and makes the display easier, I would convert the coordinates (latitude and longitude as Doubles) of each point (Pn) to integer metres south and east from the start point (P0) with something like (this isn't MC):
    Pn.x = (Pn.lon -P0.lon)*cos(P0.lat)*111120 (.toNumber())
    Pn.y = (P0.lat - Pn.lat)*111120 (.toNumber())
    Where 111120 is the number of metres in a degree of latitude (60 minutes/degree, 1 Nautical Mile (nm) per minute x 1852 metres/nm ) and
    cos(P0.lat) is used to accommodate the sphericity of the globe. It' ain't precise, but works fine for tracks up to a couple of hundred km.
    Now you have coordinates that you can scale to fit the screen.