Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Need multiple country componentRestrictions in Google Places Autocomplete

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:

like image 306
DimaS Avatar asked Dec 09 '15 13:12

DimaS


People also ask

How do I limit Google autocomplete results to city and country only?

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”} };

How do I get coordinates from autocomplete?

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.

Is Google Maps Autocomplete free?

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.


2 Answers

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.

like image 127
Sébastien Rosset Avatar answered Oct 01 '22 14:10

Sébastien Rosset


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.

like image 23
Coudrak Avatar answered Oct 01 '22 12:10

Coudrak