c# - 如何仅从 google api 获取 postal_code 数据?

标签 c# asp.net

我正在尝试从 google geocode api 获取邮政编码。

只获取邮政编码。

https://maps.googleapis.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA&key=API_KEY

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "231",
               "short_name" : "231",
               "types" : [ "street_number" ]
            },
            {
               "long_name" : "Millway Avenue",
               "short_name" : "Millway Ave",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Concord",
               "short_name" : "Concord",
               "types" : [ "sublocality_level_1", "sublocality", "political" ]
            },
            {
               "long_name" : "Vaughan",
               "short_name" : "Vaughan",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "York Regional Municipality",
               "short_name" : "York Regional Municipality",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "Ontario",
               "short_name" : "ON",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "Canada",
               "short_name" : "CA",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "L4K",
               "short_name" : "L4K",
               "types" : [ "postal_code_prefix", "postal_code" ]
            }
         ],
         "formatted_address" : "231 Millway Avenue, Vaughan, ON L4K, Canada",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 43.7991508,
                  "lng" : -79.5280784
               },
               "southwest" : {
                  "lat" : 43.7991481,
                  "lng" : -79.5280964
               }
            },
            "location" : {
               "lat" : 43.7991481,
               "lng" : -79.5280964
            },
            "location_type" : "RANGE_INTERPOLATED",
            "viewport" : {
               "northeast" : {
                  "lat" : 43.80049843029149,
                  "lng" : -79.52673841970849
               },
               "southwest" : {
                  "lat" : 43.7978004697085,
                  "lng" : -79.5294363802915
               }
            }
         },
         "partial_match" : true,
         "types" : [ "street_address" ]
      }
   ],
   "status" : "OK"
}

请帮帮我。

最佳答案

 string _Postcode = (from x in gpr.results[0].address_components.AsQueryable()
                                                where x.types.Contains("postal_code")
                                                select x.long_name).FirstOrDefault();

关于c# - 如何仅从 google api 获取 postal_code 数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27720344/

相关文章:

c# - Devexpress gridView上下文菜单项点击

c# - 在 EF4.1 中正确地从上下文附加和分离实体

c# - nopCommerce 3.70 中的 bootstrap Mega Menu

c# - 从代码加载 WPF 中的图像

asp.net - ASP.NET Web 应用程序的 SQL Server 身份验证

javascript - HTML 服务器控件与 ASP.net Web

c# - ASP.NET 3.0。无法在 POST 请求中将日期(以秒为单位)从 JSON 转换为 System.Date

c# - 应如何聚合公开子实体的信息?

c# - 在具有 3 层架构的 ASP.NET MVC 应用程序中验证业务规则的更好方法是什么?

asp.net - 具有 PNG 后备功能的浏览器中用于图像的 SVG