Search code examples
google-places-apirestrictioncountry

Google Places Autocomplete country restriction


Is there a way to make Google Places Autocomplete restricted to one country like France?

I have this: components=country:fr

https://maps.googleapis.com/maps/api/js?v=3.exp&signed_in=true&libraries=places&language=fr&components=country:fr&key=API_KEY

But this didn't restrict the autocomplete.


Solution

  • This code works for me.

    var input = document.getElementById('city_field');
        var options = {
          types: ['(cities)'],
          componentRestrictions: {country: countryCode},
            language: "en"
        };
    
        autocomplete = new google.maps.places.Autocomplete(input, options);
    

    Double check the parameter name components=country:fr syntax