i have a vehicle tracking api that I am attempting to consume in leaflet. My idea is that is the vehicle driving value is true, then update the location. Ideally, it would be if the location is different, but starting small.

Below is what I have that works for one vehicle, but am unsure how to apply this to 150 or so vehicles

var ism;

function update_position() {
    $.getJSON('http://localhost:5000/live_events', function(data) {
        var latitude = myjson._items[0]['latitude'];
        var longitude = myjson._items[0]['longitude'];
    if (!ism) {
        ism = L.marker([latitude,longitude]).bindPopup("I am driving").addTo(map);
    setTimeout(update_position, 1000);
if  (myjson._items[0]['isDriving'] = "True") {

So this would be updating every 5, 10, 15 seconds, whatever and loading under 200 vehicles. Does anyone know an optimized way to accomplish this and have it work for all vehicles?


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.