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:
How do I limit Google autocomplete results to city only? List only cities in the country var options = { types: ['(cities)'], componentRestrictions: {country: “us”} }; List all cities, states and regions in the country var options = { types: ['(regions)'], componentRestrictions: {country: “us”} };
you can retrive predictions programaticly using AutocompleteService Class with the getPlacePredictions() method [1] to retrive place_id [2]. then with this place_id you can use the Places Details Service [3] to get coordinates and more details of the place. Save this answer.
The autocomplete request is available at no charge, and the subsequent Place Details call gets charged based on regular Place Details pricing. A Place Details request generates Data SKUs (Basic, Contact, and/or Atmosphere) – depending on the fields that are specified in the request.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With