title: Can I put google map functions into a closure?
body: <p>I am trying to write some google map functionlity and playing around with javascript closures with an aim to try organise and structure my code better. </p>
  
  <p>I have the following code:</p>
  
  <pre><code>var gmapFn ={
      init : function(){
          if (GBrowserIsCompatible()) {
              this.mapObj = new GMap2($("#map_canvas"));
              this.mapObj.setCenter(new google.maps.LatLng(51.512880,-0.134334),16);
          }
      }
  }
  </code></pre>
  
  <p>Then I call it later in a jquery doc ready:</p>
  
  <pre><code>$(document).ready(function() {
      gmapFn.init();
  })
  </code></pre>
  
  <p>I have set up the google map keys and but I get an error on the main.js :</p>
  
  <p>uncaught exception: [Exception... "Component returned failure code: 0x80004005 (NS_ERROR_FAILURE)" nsresult: "0x80004005 (NS_ERROR_FAILURE)" location: "JS frame :: <a href="http://maps.gstatic.com/intl/en_ALL/mapfiles/193c/maps2.api/main.js" rel="noreferrer">http://maps.gstatic.com/intl/en_ALL/mapfiles/193c/maps2.api/main.js</a> :: ig :: line 170" data: no]
  QO()</p>
  
  <p>THe error seems to be thrown at the GBrowserIsCompatible() test which I beieve is down to  me using this closure, is there a way to keep it in an closure and get init() working?</p>