Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getCurrLatLng or getCurrentData #14

Open
silverbyte opened this issue May 25, 2019 · 4 comments
Open

getCurrLatLng or getCurrentData #14

silverbyte opened this issue May 25, 2019 · 4 comments

Comments

@silverbyte
Copy link

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

@answerquest
Copy link

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.

@answerquest
Copy link

@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);

@answerquest
Copy link

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]

@raffifu
Copy link
Contributor

raffifu commented Jul 23, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants