I'm looking to autocomplete locations of french DROM-COM (overseas administrative departments and territories) but they are not listed in the results. Here are my config :
var options = {
types: ['(regions)'],
componentRestrictions: {country: ["fr", "gp", "mq", "gf", "re", "pm", "yt", "nc", "pf", "mf", "tf"]},
strictBounds: true,
};
Regions and cities of France, Guadeloupe (gp), Martinique (mq) are shown correctly (French DOM). French CROM don't appear : Noumea in New Caledonia (nc) for instance, Tahiti, Papeete, ...
Thank you for your help.
I tried to replace "(regions)" by "geocode" but was not satisfying.
Currently, you can only use
componentRestrictions
to filter by up to 5 countriesPreviously, Google Maps Places API does not allow multiple countries to be added in the Autocomplete filter but there was a popular Feature Request to fix this. Ref: https://issuetracker.google.com/issues/35821685
When it was fixed, although it was allowed, one of the Google Engineer's comment explained that,
Ref: https://issuetracker.google.com/issues/35821685#comment236
In the same issue link above, the workaround on this is to simply use multiple requests using the AutocompleteService. This will apply to both Javascript API and the Web Service.
You can also try using
strictBounds
to restrict predictions to be strictly within a given viewport. You can use it as an alternative for regions that fit well within a rectangular region but include many countries.Another thing is that there's currently an open Feature Request to increase the current limit of 5 country restricts in Place Autocomplete requests. Ref: https://issuetracker.google.com/issues/74602145
You might want to star the issue and upvote it to subscribe to it and let Google Engineers know that you want such feature. Though there's no definite timeline if or when this would be implemented, but it would be nice if you can also put you use case there for more justification to implement such Feature.
Proof of Concept
So the issue here is not that there's no data within the aforementioned places like Noumea, Tahiti, and Papeete. It's just that their filters are being ignored because you have passed in more than 5
componentRestrictions
Removing all other components and passing only five should show that the Places API Autocomplete is working as intended. Here's a sample code:
And this should return "Noumea" just fine: