Google地方信息会在formatted_address中返回街道地址,但不会在address_components中返回

时间:2017-12-07 20:00:29

标签: javascript google-places-api google-places

对于某些地方,Google商家信息会在formatted_address字段中返回该地点的完整地址。但是,address_components中没有街道地址组件。

来自Google Places API docs

  

格式化地址在逻辑上由一个或多个地址组成   组件。

然后是:

  

不要以编程方式解析格式化的地址。相反,你   应该使用API​​响应的各个地址组件   除格式化的地址字段外还包括。

如果address_components中没有包含街道地址,我们应该以编程方式检索街道地址?

举个例子,我看到San Diego DMV location这个问题。街道地址(5858 Mt Alifan 204)未显示在address_components中,但它显示在formatted_address

{
   ...
   "result" : {
      "address_components" : [
         {
            "long_name" : "San Diego",
            "short_name" : "San Diego",
            "types" : [ "locality", "political" ]
         },
         {
            "long_name" : "Clairemont",
            "short_name" : "Clairemont",
            "types" : [ "neighborhood", "political" ]
         },
         {
            "long_name" : "San Diego County",
            "short_name" : "San Diego County",
            "types" : [ "administrative_area_level_2", "political" ]
         },
         {
            "long_name" : "California",
            "short_name" : "CA",
            "types" : [ "administrative_area_level_1", "political" ]
         },
         {
            "long_name" : "United States",
            "short_name" : "US",
            "types" : [ "country", "political" ]
         },
         {
            "long_name" : "92117",
            "short_name" : "92117",
            "types" : [ "postal_code" ]
         },
         {
            "long_name" : "4940",
            "short_name" : "4940",
            "types" : [ "postal_code_suffix" ]
         }
      ],
      ...
      "formatted_address" : "5858 Mt Alifan 204, San Diego, CA 92117, USA",
      ...
}

0 个答案:

没有答案