I'm using an API which gives real time aircraft positions.
With leaflet I use the Latitude and Longitude to display a marker of each plane on the map. I would like to move the marker when I create a new one each time my script refreshes.
setInterval(() => {
fetch("https://opensky-network.org/api/states/all")
.then((res) => {
return res.json();
})
.then((res) => {
for (let i = 0; i < res.states.length; i++) {
if (res.states[i][2] == 'France') {
if (res.states[i][5] != null || res.states[i][6] != null) {
posA = res.states[i][5];
posB = res.states[i][6];
marker = L.marker([posB, posA]);
marker.addTo(mymap);
}
}
}
})
.catch((err) => {
if (err) throw err
})
}, 3000);
I tried this but didn't work:
var newLatLng = new L.LatLng(posB, posA);
marker.setLatLng(newLatLng);