简体   繁体   中英

Google Places Autocomplete API filter by multiple countries

Looking for a way to filter the autocomplete results filtered by 2 countries, Canada and US.

Currently I can only filter by one or the other with options like this...

var options = {
  types: ['(cities)'],
  componentRestrictions: {country: 'us'}
}
var autocomplete = new google.maps.places.Autocomplete(input,options);

... but I have not seen any documentation that explains how to restrict autocomplete results to 2 countries.

Any help is appreciated.

The Google Places API does not currently support this feature. If you believe this would be a useful feature you can submit a 'Places API - Feature Request' here .

UPDATE

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 https://developers.google.com/maps/documentation/javascript/reference#ComponentRestrictions

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM