title: Unable to get property of undefined or null reference javascript
body: <p>when I launch a function from my initialize function,  I got the message </p>
  
  <p>"Unable to get property 'address_components' of undefined or null reference"</p>
  
  <p>I first add a listener</p>
  
  <pre><code>google.maps.event.addDomListener(window, 'load', initialize);
  </code></pre>
  
  <p>here is my initialize function</p>
  
  <pre><code>function initialize() {
     document.getElementById('autocomplete').value =   city()+','+countryName();  
     autocomplete = new google.maps.places.Autocomplete(
      /** @type {HTMLInputElement} */(document.getElementById('autocomplete')),
                                     {types: ['establishment','geocode']});
  
      fillInAddress();  --&gt; this call does not work
  
      google.maps.event.addListener(autocomplete, 'place_changed', function() {
                      fillInAddress();  --&gt; this call work when I change manually the value                   in                      the     field
                  });
  }
  </code></pre>
  
  <p>the following called function works when it is triggered by the above listener (place_changed)</p>
  
  <pre><code>function fillinAddress()
  
       var place = autocomplete.getPlace();
       console.log(place);    --&gt; this gives undefined  when call from initialize function
  
       for (var i = 0; i &lt; place.address_components.length; i++) {  ..  --&gt; this gives error 
  
       //Unable to get property 'address_components' of undefined or null reference
  </code></pre>
  
  <p>Any help?</p>