title: Get State and County from Address
body: <p>I want to have the State and county from an Address using geocode with Google API. This is my code:</p>
  
  <pre><code>$geocode=file_get_contents('http://maps.google.com/maps/api/geocode/json?address='.$street.''.$plz.''.$city.'&amp;sensor=false');
          $output= json_decode($geocode);
          $lat = $output-&gt;results[0]-&gt;geometry-&gt;location-&gt;lat;
          $long = $output-&gt;results[0]-&gt;geometry-&gt;location-&gt;lng;
          $formatted_adress = $output-&gt;results[0]-&gt;formatted_address;
          $state = $output-&gt;results[0]-&gt;address_components-&gt;administrative_area_level_2;
          $county = $output-&gt;results[0]-&gt;address_components-&gt;administrative_area_level_1;
  </code></pre>
  
  <p><code>latitude</code>, <code>longitude</code> and <code>formatted_adress</code> works find and I can save the results in my database, but the state and county doesn't work.</p>
  
  <p>This is the output:</p>
  
  <pre><code>    {
     "results" : [
        {
           "address_components" : [
              {
                 "long_name" : "Hauptgasse",
                 "short_name" : "Hauptgasse",
                 "types" : [ "route" ]
              },
              {
                 "long_name" : "Solothurn",
                 "short_name" : "Solothurn",
                 "types" : [ "locality", "political" ]
              },
              {
                 "long_name" : "Solothurn",
                 "short_name" : "Solothurn",
                 "types" : [ "administrative_area_level_2", "political" ]
              },
              {
                 "long_name" : "Solothurn",
                 "short_name" : "Südost",
                 "types" : [ "administrative_area_level_1", "political" ]
              },
              {
                 "long_name" : "Schweiz",
                 "short_name" : "CH",
                 "types" : [ "country", "political" ]
              },
              {
                 "long_name" : "4500",
                 "short_name" : "4500",
                 "types" : [ "postal_code" ]
              }
           ],
           "formatted_address" : "Hauptgasse, 4500 Solothurn, Schweiz",
           "geometry" : {
              "bounds" : {
                 "northeast" : {
                    "lat" : 47.2088079,
                    "lng" : 7.540025399999999
                 },
                 "southwest" : {
                    "lat" : 47.2065432,
                    "lng" : 7.535295899999999
                 }
              },
              "location" : {
                 "lat" : 47.20778,
                 "lng" : 7.537360000000001
              },
              "location_type" : "GEOMETRIC_CENTER",
              "viewport" : {
                 "northeast" : {
                    "lat" : 47.20902453029149,
                    "lng" : 7.540025399999999
                 },
                 "southwest" : {
                    "lat" : 47.20632656970849,
                    "lng" : 7.535295899999999
                 }
              }
           },
           "partial_match" : true,
           "place_id" : "ChIJS4BfGfnXkUcRqLUKnJzN54U",
           "types" : [ "route" ]
        }
     ],
     "status" : "OK"
  }
  </code></pre>