Francois
Francois

Reputation: 10631

Google Places Autocomplete

I am using google.maps.places.Autocomplete, I want city to autocomplete but restrict the autocomplete results to multiple cities, not just one as in the google documentation.

this is what I have

<script src="http://maps.googleapis.com/maps/api/js?sensor=false&amp;libraries=places" type="text/javascript"></script>
<script type="text/javascript">
 function initialize() {

    var input = document.getElementById('searchTextField');

    /* restrict to multiple cities? */
    var options = {
       types: ['(cities)'],
       componentRestrictions: {country: "us", "fr"}
    };


    var autocomplete = new google.maps.places.Autocomplete(input, options);
 }
 google.maps.event.addDomListener(window, 'load', initialize);
</script>

<div>
<input id="searchTextField" type="text" size="50" placeholder="Enter a location" autocomplete="on">
</div>

Upvotes: 2

Views: 5634

Answers (3)

prestarocket
prestarocket

Reputation: 753

You can only add 1 country for restrictions. https://developers.google.com/maps/documentation/javascript/reference#ComponentRestrictions

Upvotes: 0

sgimeno
sgimeno

Reputation: 1893

Actually the Places API supports only 1 country as restriction. ComponentRestrictions

Upvotes: 3

Naor
Naor

Reputation: 24053

I am new to google places autocomplete but I think the error is here:

componentRestrictions: {country: "us", "fr"}

Try this:

componentRestrictions: {country: ["us", "fr"]}

Upvotes: 1

Related Questions