In my application I listen to the Google Maps API 'bounds_changed' event to send an ajax request to update some div on the web page depending on the new boundaries of the map:
google.maps.event.addListener(map, 'bounds_changed', function() {
// here goes an ajax call
}
The event 'bounds_changed' is fired with a high frequency when the user drag the map around. So much that there are too many ajax requests sent to the server.
Basically I would like to make the ajax call only after the user has stopped to move the map during some time period (for example 500ms). I am not very experienced with Javascript and tried to achieve this with setTimeout and clearTimeout but without success.
Any idea would be appreciated :)
The addEventListener method is the most preferred way to add an event listener to window, document or any other element in the DOM. There is one more way called “on” property onclick, onmouseover, and so on.
TF: if an event occurs and there is not event handler to respond to that event, the event ins ignored.
google suggests using another listener ...
google.maps.event.addListener(map, 'idle', showMarkers);
quote "Note that you could listen to the bounds_changed event but it fires continuously as the user pans; instead, the idle will fire once the user has stopped panning/zooming." /quote
see
http://code.google.com/apis/maps/articles/toomanymarkers.html#gridbasedclustering
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With