2
votes

I'm using V3 of the Google maps javascript api to bring in more markers as the map bounds are changed. The problem is that when I drag the map around for a while and then end dragging a flood of events are triggered at once. They appear to be queueing up while the map is being dragged.

Is there some way I can add a timer to stop this or will I have to use the zoom_changed and dragend events as a workaround?

Here is the relivant code:

google.maps.event.addListener(map, 'bounds_changed', function() {
  var bounds_url = map.getBounds().toUrlValue();
  $.ajax({
    //... 
  });
});
2
I faced the same problem and used the zoom_changed and dragengArgiropoulos Stavros

2 Answers

1
votes

Add a timeout, that runs your code 500ms after the event fires, each time the event fires clear the timeout and create a new one.

google.maps.event.addListener(map, 'bounds_changed', (function () {
    var timer;
    return function() {
        clearTimeout(timer);
        timer = setTimeout(function() {
            // here goes an ajax call
        }, 500);
    }
}()));
1
votes

This is known bug , google team recommends using:

google.maps.event.addListener(map, 'idle', function() { });