title: how to read city ,state,country from google map geocoding json data
body: <p>I'm using .net MVC 3 and Google Maps v3. I'd like to do geocoding in an action. That is passing a valid address to Google and getting the city,state and country back. How would you do this in an action using C#?</p>
  
  <pre><code>    [HttpPost]
      public ActionResult getLocation(string pincode)
      {
          string url = "http://maps.googleapis.com/maps/api/geocode/json?
           sensor=true&amp;address=";
          var data="";
          dynamic googleResults = new Uri(url + 
           pincode).GetDynamicJsonObject();
          foreach (var result in googleResults.results)
          {
  
              data= "[" + result.geometry.location.lat + "," + 
           result.geometry.location.lng + "] " + result.formatted_address;
          }
          return Json("Successful" + data, JsonRequestBehavior.AllowGet);
      }
  </code></pre>
  
  <p>this is json data which i am getting from google geocoding from which i wants to read city,state and country from address_components types administrative_area_level_2,administrative_area_level_1,country</p>
  
  <pre><code>{
     "results" : [
        {
           "address_components" : [
              {
                 "long_name" : "411022",
                 "short_name" : "411022",
                 "types" : [ "postal_code" ]
              },
              {
                 "long_name" : "SRPF",
                 "short_name" : "SRPF",
                 "types" : [ "political", "sublocality", "sublocality_level_2" ]
              },
              {
                 "long_name" : "Wanowrie",
                 "short_name" : "Wanowrie",
                 "types" : [ "political", "sublocality", "sublocality_level_1" ]
              },
              {
                 "long_name" : "Pune",
                 "short_name" : "Pune",
                 "types" : [ "locality", "political" ]
              },
              {
                 "long_name" : "Pune",
                 "short_name" : "Pune",
                 "types" : [ "administrative_area_level_2", "political" ]
              },
              {
                 "long_name" : "Maharashtra",
                 "short_name" : "MH",
                 "types" : [ "administrative_area_level_1", "political" ]
              },
              {
                 "long_name" : "India",
                 "short_name" : "IN",
                 "types" : [ "country", "political" ]
              }
           ],
           "formatted_address" : "SRPF, Wanowrie, Pune, Maharashtra 411022, India",
           "geometry" : {
              "bounds" : {
                 "northeast" : {
                    "lat" : 18.5065017,
                    "lng" : 73.9128001
                 },
                 "southwest" : {
                    "lat" : 18.4966367,
                    "lng" : 73.90290019999999
                 }
              },
              "location" : {
                 "lat" : 18.4986371,
                 "lng" : 73.9074389
              },
              "location_type" : "APPROXIMATE",
              "viewport" : {
                 "northeast" : {
                    "lat" : 18.5065017,
                    "lng" : 73.9128001
                 },
                 "southwest" : {
                    "lat" : 18.4966367,
                    "lng" : 73.90290019999999
                 }
              }
           },
           "place_id" : "ChIJQ1UppdzBwjsRPIND-6yqBNI",
           "types" : [ "postal_code" ]
        }
     ],
     "status" : "OK"
  }
  </code></pre>