12

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. So, is there a way to get results with multiple counties in Google Places Autocomplete?

My page is copy-paste from Place Autocomplete Address Form example:

xomena
  • 31,125
  • 6
  • 88
  • 117
DimaS
  • 571
  • 2
  • 5
  • 19
  • 1
    There is already a [feature request](https://code.google.com/p/gmaps-api-issues/issues/detail?id=4233) in the Google Maps issue tracker. Currently there is no way to restrict multiple countries by using the `componentRestrictions`. – ztan Dec 09 '15 at 23:21
  • Workaround here: http://stackoverflow.com/questions/11290755/limit-google-maps-of-countries-in-the-autocomplete-list-to-india-usa-and-uk/36064059#36064059 – metamagikum Mar 17 '16 at 14:54

3 Answers3

17

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.

Sébastien Rosset
  • 1,481
  • 1
  • 10
  • 17
  • 1
    Thank you! Here's the [reference](https://developers.google.com/maps/documentation/javascript/reference/places-autocomplete-service#ComponentRestrictions) that confirms this. – Greg Sadetsky May 26 '22 at 20:58
12

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

xomena
  • 31,125
  • 6
  • 88
  • 117
  • 1
    I wonder why they build in the arbitrary restriction to five countries. Probably because they think US plus oversea departments is enough. – Michael K. Feb 19 '18 at 10:06
11

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.

shim
  • 9,289
  • 12
  • 69
  • 108
Coudrak
  • 111
  • 1
  • 4