【发布时间】:2019-03-04 01:35:41
【问题描述】:
我们有一个使用 google maps api 自动填写城市详细信息字段的自动完成字段
因此,使用“(城市)”作为类型,我们会得到一个与搜索结果匹配的城市列表,但是数据并不一致,而且澳大利亚的大城市缺少诸如邮政编码字段之类的内容。如下查找
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" ]
}
],
带有“postal_code”和“locality”、“political”
但是在墨尔本搜索你会期望邮政编码 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”、“locality”、“political”中,并且没有“postal_code”
但是,在自动完成功能中过滤墨尔本时,您得到的只是墨尔本选项或墨尔本机场,两者都不正确。如果您随后将类型更改为“(地区),您可以搜索返回正确墨尔本版本的邮政编码。
有没有人遇到过这种情况并想出了一种方法来强制过滤结果只显示带有邮政编码的版本?
【问题讨论】:
-
大城市没有唯一的邮政编码
标签: google-maps