how to change value of a var in reverse geocoding function : <p>I am trying to get address info for my project. I can see the address by alert() method if i write it inside the geocode function. but if i outside of the function, it returns <strong>undefined</strong>. </p>

<p>tried to write the variable name like <strong>window.adres</strong> but didnt work. i think because of an another function with is parent of this.</p>

<p>how to make that variable global and change the value? </p>

<pre><code>var geocoder = new google.maps.Geocoder;
var adres;

 var latlng = {lat: parseFloat(lat), lng: parseFloat(lon)};
    geocoder.geocode({'location': latlng}, function(results, status) {
      if (status === 'OK') {
        if (results[0]) {
         adres = results[0].formatted_address;
         //window.adres = ... is not working. i think because of an another function which is parent of these lines.
          alert(adres); //returns address   
        } 
      } else {
        window.alert('Geocoder failed due to: ' + status);
      }

 alert(adres); //returns undefined
</code></pre>

<p>also i tried that</p>

<pre><code>var geocoder = new google.maps.Geocoder;


 var latlng = {lat: parseFloat(lat), lng: parseFloat(lon)};
    var adres = geocoder.geocode({'location': latlng}, function(results, status) {
      if (status === 'OK') {
        if (results[0]) {
         return results[0].formatted_address;

        } 
      } else {
        window.alert('Geocoder failed due to: ' + status);
      }

 alert(adres); //returns undefined too
</code></pre>
