谷歌地图城市搜索

时间:2019-03-04 01:35:42

标签: google-maps

我们有一个使用Google Maps API的自动填充字段来自动填写城市详细信息字段

因此,使用“(cities)”作为类型,我们会得到匹配搜索条件的城市列表,但是数据不一致,而且澳大利亚的大型城市缺少诸如postal_code字段之类的内容。查找如下

 this.autocomplete = new google.maps.places.Autocomplete((this.element), { types: ["(cities)"] , componentRestrictions: {country: ["au","nz"]}});

因此,在诸如“里士满”之类的郊区搜索城市时,您会得到以下响应

/**/_xdc_._n1gyyx && _xdc_._n1gyyx( {
   "html_attributions" : [],
   "result" : {
      "address_components" : [
         {
            "long_name" : "Richmond",
            "short_name" : "Richmond",
            "types" : [ "locality", "political" ]
         },
         {
            "long_name" : "Yarra City",
            "short_name" : "Yarra",
            "types" : [ "administrative_area_level_2", "political" ]
         },
         {
            "long_name" : "Victoria",
            "short_name" : "VIC",
            "types" : [ "administrative_area_level_1", "political" ]
         },
         {
            "long_name" : "Australia",
            "short_name" : "AU",
            "types" : [ "country", "political" ]
         },
         {
            "long_name" : "3121",
            "short_name" : "3121",
            "types" : [ "postal_code" ]
         }
      ],

带有“邮政编码”和“地区”,“政治”

不过,在墨尔本搜索时,您会希望获得邮政编码为3000的详细信息,但是您只会得到

/**/_xdc_._ntt86i && _xdc_._ntt86i( {
   "html_attributions" : [],
   "result" : {
      "address_components" : [
         {
            "long_name" : "Melbourne",
            "short_name" : "Melbourne",
            "types" : [ "colloquial_area", "locality", "political" ]
         },
         {
            "long_name" : "Victoria",
            "short_name" : "VIC",
            "types" : [ "administrative_area_level_1", "political" ]
         },
         {
            "long_name" : "Australia",
            "short_name" : "AU",
            "types" : [ "country", "political" ]
         }
      ],

因此,现在名称存储在“ colloquial_area”,“位置”,“政治”中,并且没有“邮政编码”

但是在自动完成功能中过滤墨尔本时,您得到的只是墨尔本选项或墨尔本机场,都不正确。然后,如果您将类型更改为“(地区),则可以搜索会返回正确的墨尔本版本的邮政编码。

有人遇到过这种情况,并找到了一种方法来强制过滤后的结果仅显示带有邮政编码的版本吗?

1 个答案:

答案 0 :(得分:0)

此行为按预期进行,因为像墨尔本这样的地方在其区域内有多个邮政编码(例如3977、3156、3806、3978等),因此,结果不会返回邮政编码,因为它不是要处理的多个邮政编码,并且不能返回单个邮政编码,因为这将影响信息的完整性,因为它将不适用于其余的邮政编码。

您可以在Issue Tracker中提出功能请求,以请求这种处理多种邮政编码的功能。