title: Google Geocoding v3 - Getting formatted Address
body: <p>I was wondering if anyone is able to help me. I am having a hard time getting both the coordinates and the formatted address returned to me in my dialogue box on my geocoding result, even though I seem to be able to grab the city, country. </p>
  
  <p>Here is the code I am working with:</p>
  
  <pre><code>http://jsfiddle.net/d5DBh/5/
  </code></pre>
  
  <p>Code</p>
  
  <pre><code>var myLatlng = new google.maps.LatLng(31.272410, 0.190898);
  
  
   // INITALIZATION
   function initialize() {
       var mapOptions = {
           zoom: 4,
           center: myLatlng,
           mapTypeId: google.maps.MapTypeId.ROADMAP
       }
       var map = new google.maps.Map(document.getElementById("map-canvas"), mapOptions);
   }
  
  
   // GEOCODE
   function codeAddress() {
       var address = document.getElementById("address").value;
       new google.maps.Geocoder().geocode({
           'address': address
       }, function (results, status) {
           if (status == google.maps.GeocoderStatus.OK) {
               if (results[0]) {
                   var address = "",
                       city = "",
                       town = "",
                       state = "",
                       country = "",
                       location = "",
                       format = "";
                   for (var i = 0; i &lt; results[0].address_components.length; i++) {
                       var addr = results[0].address_components[i];
                       if (addr.types[0] == 'country') country = addr.short_name;
                       else if (addr.types[0] == 'street_address')
                       address = address + addr.long_name;
                       else if (addr.types[0] == 'route')
                       address = address + addr.long_name;
                       else if (addr.types[0] == ['administrative_area_level_1'])
                       state = addr.long_name;
                       else if (addr.types[0] == ['administrative_area_level_2'])
                       town = addr.long_name;
                       else if (addr.types[0] == ['locality'])
                       city = addr.long_name;
                       else if (addr.types[0] == ['location'])
                       location = addr.location;
                   }
                   alert('Formated Address: ' + format + '\n' + 'City: ' + city + '\n' + 'Town: ' + town + '\n' + 'State: ' + state + '\n' + 'Country: ' + country + '\n' + 'Coordinates: ' + location);
               }
       } else {
           alert("Error: We could not find this address - please try and different location");
       };
       });
   }
  
   initialize();
   document.getElementById("searchItem").onclick = function () {
       codeAddress();
       return false;
   };
  </code></pre>
  
  <p>Also, since I am new to Javascript I am open to any ideas about writing this more cleanly. </p>