Save the data in a database table or json on file, as you prefer.
But you need to have the time you were registered and position to be able to plot the route.
You need to set a time interval or distance to be recorded, for example every 5 meters or 1min you save the position.
Example.
The pattern to follow depends on the need to trace the route ... The most used for tracking. it is for example: if the position of distance exceeds 5 meters, it records the change, remembering that it is necessary to define a ray for tolerance, since GPS does not always maintain the precision.
In the image posted every time I registered the position, then even stopped at the same place the GPS returned different values, I did not tolerate and distance the old position.