title: google maps fitBounds callback
body: <p>I know there is a <code>bounds_changed</code> event that is triggered if the bounds have changed, however I need to know when fitBounds has completed (when bounds have changed or bounds have stayed the same).</p>
  
  <p>Google has some sort of tolerance where if the bounds have changed very little it will not actually change the bounds / call bounds_changed. I need to know when this happens.</p>
  
  <p>I have done this successfully with timeouts but it seems hacky and possibly prone to some errors when bounds_changed take more than 100ms to trigger.</p>
  
  <p>See example: <a href="http://jsbin.com/sosurexuke/1/edit?js,console,output" rel="nofollow noreferrer">http://jsbin.com/sosurexuke/1/edit?js,console,output</a></p>
  
  <p>Any better solutions?</p>
  
  <p>Edit: If you think just checking if the map.getBounds() is the same as what you are sending fitBounds() then you'll be disappointed to know that the result of fitting to bounds is typically not even close to the bounds you send. I wrote this function thinking this might be possible</p>
  
  <pre><code>function boundsAreIdentical(bounds1, bounds2) {
          if (!bounds1 || !bounds2) return false;
  
          var tolerance = 0.00001;
          console.log(bounds1.getNorthEast().lat(), bounds2.getNorthEast().lat());
          console.log(bounds1.getNorthEast().lng(), bounds2.getNorthEast().lng());
          console.log(bounds1.getSouthWest().lat(), bounds2.getSouthWest().lat());
          console.log(bounds1.getSouthWest().lng(), bounds2.getSouthWest().lng());
          if (
              (Math.abs(bounds1.getNorthEast().lat() - bounds2.getNorthEast().lat()) &lt;= tolerance) &amp;&amp;
              (Math.abs(bounds1.getNorthEast().lng() - bounds2.getNorthEast().lng()) &lt;= tolerance) &amp;&amp;
              (Math.abs(bounds1.getSouthWest().lat() - bounds2.getSouthWest().lat()) &lt;= tolerance) &amp;&amp;
              (Math.abs(bounds1.getSouthWest().lng() - bounds2.getSouthWest().lng()) &lt;= tolerance)) {
              return true;
          }
          return false;
      }
  </code></pre>
  
  <p>Edit 2 years later:</p>
  
  <p>It seems that in the latest experimental version of google maps (3.32) <code>bounds_changed</code> is fired even when the bounds are identical to current bounds.</p>
  
  <p>I updated the original example to be version 3.31 which still shows the original issue.</p>