Search code examples
google-mapsstreet-address

Google Address Suggestions country restrictions does not working properly


To add country restrictions for google address suggestions, we can just add

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

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

It's working fine as expected. But If I add more countries like below then I don't see addresses for few countries US, UK, FR etc:

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"]});

Debugging Result:

I found after CN countries not getting restricted. So I thought may be Issue with incorrect country code. But all codes are correct.

I thought may be issue with country code CY (Cyprus). But If I use. It's working.

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

Not getting what is the issue. Anyone faced Issue like this?


Solution

  • You can only provide a maximum of five country codes. See the 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.