title: start script only after google maps initialise load
body: <p>I'm am writing javascript code to fill a field with the coordinates of a google api map.
  The problem is however that the initialization of the google map </p>
  
  <pre><code>&lt;script type="text/javascript"&gt;
  
    var coord,mapOptions,map;
    function initialize() {
      coord = new google.maps.LatLng(-25.363882, 131.044922);
      mapOptions = { zoom: 4, center: coord , mapTypeId: google.maps.MapTypeId.ROADMAP};
      map = new google.maps.Map(document.getElementById('map_canvas'), mapOptions);
   }
  
   function getBounds(map,currentv)
   {
     currentv[0] = map.getCenter().lat();
     currentv[1] = map.getCenter().lng();
     return currentv;
   }
   &lt;/script&gt;
  </code></pre>
  
  <p>happens (as i understand it; i've just began with js) after all the other code has loaded. </p>
  
  <pre><code>&lt;script&gt;
    if (map != undefined){
      currentv = getBounds(map,currentv);
      console.log("Debug: lat "+currentv[0]);
      document.write('&lt;input type="text" name="latitude" value="'+ currentv[0] +'" /&gt;');
    } 
  &lt;/script&gt;
  </code></pre>
  
  <p>So somewhere below sits this code to fill the field but it's loaded before the initialize(); and then after it's not run anymore?</p>
  
  <p>How can i solve this problem?</p>
  
  <p>edit: (added the event listener which i had left out)</p>
  
  <pre><code>google.maps.event.addListener(map, 'bounds_changed', function() { window.setTimeout(function() { 
  
  map.panTo(marker.getPosition());
  map.setZoom(4);
  getBounds(map,currentv); 
  
  }, 3000); });
  </code></pre>