getCurrLatLng or getCurrentData
getCurTime is great to get the current time, it would be even greater if it can return back current latlng along with Info. Example getCurrentData { lat: lng: Info: }. Maybe this would be heavy for multiple tracks but for single track would be good
Really really needed! If I'm console-logging the objects, I can see there's arrays inside having all this info, but I'm not able to get this out currently.
@silverbyte I found a way to get it! Take a look:
trackplayback.on('tick', e => {
$('.info-cur-time').append(` ( ${parseInt(trackplayback.getCurTime())} )`);
// console.log(trackplayback);
// console.log(trackplayback.clock._trackController._draw._bufferTracks[0]); // this seems to be all the preceding points
var bufferTracks = trackplayback.clock._trackController._draw._bufferTracks[0];
// this json array holds all the points travelled uptill now with lat-longs, and if this is an interpolation then the interpolated point at the end.
var latestPoint = bufferTracks[bufferTracks.length - 1];
/* looks like: {"lat":12.9711727,"lng":80.2438891,"time":1564745951,"info":[{"key":"user","value":"test3"},..],"isOrigin":true} */
if(! latestPoint['isOrigin'] && bufferTracks.length>1) {
// if the last element in the array is an interpolated point, then take the second-last element which will hold the last reported GPS location.
latestPoint = bufferTracks[bufferTracks.length - 2];
}
console.log(latestPoint);
$('#currentLocation').html(`${parseFloat(latestPoint['lat']).toFixed(5)},${parseFloat(latestPoint['lng']).toFixed(5)}`);
//map.setView(latestPoint); // for making the map follow the track. But danger : this is preventing rendering of the boat icon for some reason. Uncomment only if you're ok with losing that icon.
}, this);
When we do console.log(trackplayback), a whole big complex object comes in browser console. I rummaged through it all, tried and failed at many places, finally got some headway in .clock._trackController._draw._bufferTracks[0]
If you want to use public method you can do it by calling getTrackPointsBeforeTime from tracks
trackplayback.on('tick', e => {
const rendered = trackplayback.tracks[0].getTrackPointsBeforeTime(e.time)
if (rendered.length > 1) {
const lastRendered = rendered[rendered.length - 2]
console.log(lastRendered.info)
}
}, this)
drawback from above code is the method executed 2 times