Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>One quick and dirty solution would be to call the server less frequently:</p> <pre><code>var requestCounter = 0; var frequency = 50; google.maps.event.addListener(map, 'bounds_changed', function() { if((++requestCounter % frequency) == 0){ // here goes an ajax call (also, optionally reset the counter here) } }); </code></pre> <p>Alternatively, I've done something similar where I've reset a timer every time I "heard from" the user. Once the timer expired, it called my action. So the timer continuously tries to go off but if the user does something, the timer is reset. Eventually, the user stops moving long enough that the timer has a chance to trigger it's event.</p> <p><hr> EDIT:<br> Along the lines of:</p> <pre><code>google.maps.event.addListener(map, 'bounds_changed', userInput); function userInput() { resetTimer(); } </code></pre> <p>Where resetTimer() clears/starts your timer. That would look something like:</p> <pre><code>var inputTimer = null; var timeLimit = 500; function resetTimer() { if(inputTimer != null) clearInterval(inputTimer); inputTimer = setTimeout('contactServer()', timeLimit); } function contactServer() { // here goes an ajax call } </code></pre> <p>I haven't tested that this compiles but it should give you the basic idea. This code has the advantage of being modular enough to work in many other languages with only minor edits. I follow a similar logic in ActionScript. Also, it's extremely easy to read, follow logically and maintain (6 months later when you forget how your code works).</p> <p>I hope that helps in some way,</p> <p>--gMale</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload