title: google places autocomplete API get town and region (JavaScript)
body: <p>I think this is a new question and I have some example code.</p>
  
  <p>The code for google places autocomplete API is:</p>
  
  <pre><code>      function initialize() {
          var input = document.getElementById('searchField');
          var options = {
          componentRestrictions: {
          country: ['uk', 'ie']
          }
        };
        var autocomplete = new google.maps.places.Autocomplete(input, options);
        google.maps.event.addListener(autocomplete, 'place_changed', 
        function() {
           var place = autocomplete.getPlace();
           var placeStreet = autocomplete.getPlace()[0];
           var place_ = place.name;
           var lat_ = place.geometry.location.lat();
           var long_ = place.geometry.location.lng();
           alert(place + ", street:  " + placeStreet + ", " + place_ + ", " + 
           lat_ + ", " + long_);
  
         });
       }
  </code></pre>
  
  <p>How do I get the town or region or country.  As I'm from the UK, I need to detect town such as london, region or county = middlesex and country = United Kingdom.  Is there anyway to do this? and how do I find the printout of getPlace() how do I get the Javascript object printed out.</p>
  
  <p>Thanks in advance</p>
  
  <p>***EDIT JSON.stringify(autocomplete.getPlaces()) prints out the object but how do I extract town, region, country etc.</p>
  
  <p>*** EDIT In my autocomplte my json object prints out objects in different orders so finding the 3 rd object will be postal town or administrative area.   How do I search by type and get type country and the country or type postal_town and town.  My json outputs are:</p>
  
  <p>1)</p>
  
  <pre><code>     {
        "address_components": [
        {
        "long_name": "12-20",
        "short_name": "12-20",
        "types": [
         "street_number"
        ]
        },
        {
        "long_name": "Wood Street",
        "short_name": "Wood St",
        "types": [
         "route"
         ]
        },
        {
         "long_name": "Walthamstow",
          "short_name": "Walthamstow",
          "types": [
          "neighborhood",
          "political"
         ]
       },
       {
        "long_name": "London",
        "short_name": "London",
         "types": [
         "postal_town"
        ]
        }, etc
  </code></pre>
  
  <p>2)</p>
  
  <pre><code> {
      "address_components": [
      {
       "long_name": "London",
        "short_name": "London",
       "types": [
        "locality",
        "political"
      ]
     },
     {
    "long_name": "London",
    "short_name": "London",
    "types": [
      "postal_town"
    ]
      },
       {
          "long_name": "Greater London",
          "short_name": "Greater London",
          " types": [
          "administrative_area_level_2",
         "political"
       ]
       },
  </code></pre>