Need help updating markers when map is moved

The code I have show a map and shows some markers from my own custom api.
The issue is I have set these markers to update in onMapPanningEnded(). And in that function there is:
// code to add a marker
The issue is the new marker is not showing. If I zoom, it shows, but when I stop zooming it disappears (Because onMapPanningEnded() was called).
I tried to add ZoomIn() and zoomOut() after my code and it then started showing the markers correctly. But having the map zoom in and out whenever a user moves is not a sane fix.
Is there any function I can call to refresh the markers on the map? Or am I adding the points on movement wrong?
Thanks for reading

It turned out that clear() and removeMarkers() were not the issue, as I removed them and the issue was still there. I removed the thread call from the panning callback and the issue was gone. But the only thing the callback does is it runs the thread that I already run once the map is ready, so I know the thread is not the issue; as the only thing it does is add the markes. So what is causing the markers to disappear?

For anyone who has the same issue, using the on camera move event handler to call the markers thread seems to have worked (Your documentation should really include details like where marker updating should be put)