Google 地址建议国家/地区限制无法正常工作

Google Address Suggestions country restrictions does not working properly

要为 google 地址建议添加国家/地区限制,我们只需添加

autocomplete.setComponentRestrictions({"country":["US"]}); //Display US address only

autocomplete.setComponentRestrictions({"country":["US","CA"]}); //Display US, CA only

按预期工作正常。但是,如果我像下面这样添加更多国家/地区,那么我看不到美国、英国、法国等少数国家/地区的地址:

autocomplete.setComponentRestrictions({"country":["AU","AT","BE","CA","CN","CY","EE","FI","FR","DE","GR","HK","IE","IT","JP","LV","LT","LU","MT","MC","NL","PT","SK","SI","ES","GB","US"]});

调试结果:

我发现CN国家之后没有被限制。所以我认为可能是国家代码不正确的问题。但是所有代码都是正确的。

我认为国家代码 CY(塞浦路斯)可能有问题。 但是如果我使用。有效。

autocomplete.setComponentRestrictions({"country":["CY"]}); //只显示CY地址

不明白是什么问题。有人遇到过这样的问题吗?

您最多只能提供五个国家代码。见 documentation:

Restricts predictions to the specified country (ISO 3166-1 Alpha-2 country code, case insensitive). For example, 'us', 'br', or 'au'. You can provide a single one, or an array of up to five country code strings.