Help needed with creating a line on map

Hello again,

I recently posted asking help for reading the gps co-ordinates from a json string on thingspeak.

I am now trying to figure out how to create a line string that joins to the new location everytime the gps co-ordinates move.

Ideally i have two buttons, one to start the tracking and drawing of the line and other button to clear all current lines.

This is part of the code so far where I create the marker and ensure that the old ones are deleted as the gps co-ordinates update.

The line string would however remain and show the "path" the gps took.
Ignore the two calls, both are really broken based on me trying to adapt online guides for what i need. Most guides seem to use inbuilt phone gps, while i'm reading from a json string on teamspeak to read long and lat.

ANY help would be much appreciated as i'm stumped.

Try like this:

For demo purposes I have used touch map to generate a marker but you can use your logic when your lat/lon arrives. This code leaves the first marker displayed, but hides all others, you could have a routine to allow for the last marker to be displayed in a different colour ?

Note: the lines drawn will be "as the crow flies", they will not follow roads on the map.

image

2 Likes

Improved...smaller marker and shows end marker in green

image

2 Likes

Hello!

Thanks for the help!

I've tried to implement your code into mine, whilst changing it a bit so that I can start and stop the tracking. However I've run into several issues.

Firstly the line doesn't show up at all, nor the start marker. Secondly when I turn off tracking the marker just disappears. Is it possible to keep the lines and marker until I press clear or start a new run?

Essentially I hope to have 3 markers, 1 live marker that shows current position.

Then when i press start tracking it does what you showed me. When i press stop, it should hopefully just remain there until i clear it.

any thoughts?


This is my code so far.

From what I can see in your blocks, you are not adding the first marker coordinates to the points list (see my blocks again). I would also have a look at the use if if global track - true this could be why your line is not showing. If stopping the timer hides everything, you may need to manaully reshow your line using the points and marker lists.

What did you put in your lines formatting when you dragged it to the map module? I keep breaking everything lol

All I did was drag out one (and only one) linestring to the map, left all the defaults as they were, and set it to not visible. That produced the thin black line in my images above.

hmm, would getting the same co-ordinates break things? I'm thinking i have to rewrite the code to allow 2 separate functions. one to get current position and one to allow tracking and lines. How this works with the clock confuses me