Need multiple country componentRestrictions in Google Places Autocomplete

后端 未结 3 480
后悔当初
后悔当初 2020-12-19 01:04

I need Google Places Autocomplete to give me results from countries: SZ, FR, DE, AT, IT. I know that componentRestrictions can operate with only one country. S

相关标签:
3条回答
  • 2020-12-19 01:12

    Be careful because if you restrict to "FR", it ignores the French overseas departments. So to have the cities in all of France, you need:

    'fr', 'gp', 're', 'mq', 'gf', 'nc', 'yt', 'pf'
    

    But since it's more than 5, it's not possible to limit to the whole of France.

    Google Maps considers that the French overseas departments are not in France; this is a big problem.

    0 讨论(0)
  • 2020-12-19 01:27

    Since version 3.2.7, you can use an array for componentRestrictions. Eg:

    { country: ["fr","ch","be"] }
    

    The number of countries is, however, restricted to 5.

    0 讨论(0)
  • 2020-12-19 01:33

    This feature was introduced in version 3.27 of Maps JavaScript API in January 2017:

    You can now restrict Autocomplete predictions to only surface from multiple countries. You can do this by specifying up to 5 countries in the componentRestrictions field of the AutocompleteOptions.

    https://developers.google.com/maps/documentation/javascript/releases#327

    0 讨论(0)
提交回复
热议问题