Google Maps overlay positioning issues after map dragging events

I’m working with Google Maps and having trouble with overlay positioning. When the map loads for the first time, my markers show up in the right spots. But when I drag the map around, the new markers I add appear in wrong locations.

Here’s what happens: I fetch location data from an external service during the map’s idle event, then add markers based on those coordinates. The first set of markers works fine, but after dragging the map and getting new data, those markers are positioned incorrectly. Strangely, when I drag again, the previous markers fix themselves but the newest ones are still wrong.

I think the problem might be that the overlay positioning doesn’t consider the updated map boundaries. The data fetching and marker drawing happens asynchronously, which might be causing this issue. Has anyone experienced similar positioning problems with Google Maps overlays?

sounds like a timing issue with the projection. try adding a small delay before placing markers, or check if the map projection’s ready first. i had the same prob - was adding markers while the map was still updating internally after the drag ended.

Been there - super frustrating. The map bounds aren’t fully updated when you’re calculating where to put markers. I switched from using the idle event to bounds_changed and that helped a lot. The bounds need to be completely settled before you position new overlays. Also, timing matters with getProjection() - call it too early during dragging and you’ll get outdated data. I ended up adding a 100ms setTimeout after bounds_changed fires. Gives the map time to finish its internal updates before placing markers.

Had this exact issue last year. Google Maps caches the projection matrix during drags, so your async data uses stale coordinate transformations. I fixed it by storing the map center and zoom when the drag starts, then recalculating marker positions with those saved values instead of the current map state. Hook into the dragstart event to capture these values. Also don’t mix up pixel coordinates with lat/lng during conversion - another gotcha I hit. The projection methods give inconsistent results while the map’s transitioning.