I am using google.maps.places.Autoplete, I want city to autoplete but restrict the autoplete results to multiple cities, not just one as in the google documentation.
this is what I have
<script src=";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)'],
ponentRestrictions: {country: "us", "fr"}
};
var autoplete = new google.maps.places.Autoplete(input, options);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<div>
<input id="searchTextField" type="text" size="50" placeholder="Enter a location" autoplete="on">
</div>
I am using google.maps.places.Autoplete, I want city to autoplete but restrict the autoplete results to multiple cities, not just one as in the google documentation.
this is what I have
<script src="http://maps.googleapis./maps/api/js?sensor=false&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)'],
ponentRestrictions: {country: "us", "fr"}
};
var autoplete = new google.maps.places.Autoplete(input, options);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
<div>
<input id="searchTextField" type="text" size="50" placeholder="Enter a location" autoplete="on">
</div>
Share
Improve this question
asked Apr 16, 2012 at 8:03
FrancoisFrancois
10.7k5 gold badges55 silver badges65 bronze badges
2
- Ironically, this is the first example that I have found for filtering by country. Thanks! Where did you go for documentation btw? – fatfrog Commented Nov 30, 2014 at 22:06
- Workaround here: stackoverflow./questions/11290755/… – metamagikum Commented Mar 17, 2016 at 14:55
3 Answers
Reset to default 3Actually the Places API supports only 1 country as restriction. ComponentRestrictions
I am new to google places autoplete but I think the error is here:
ponentRestrictions: {country: "us", "fr"}
Try this:
ponentRestrictions: {country: ["us", "fr"]}
You can only add 1 country for restrictions. https://developers.google./maps/documentation/javascript/reference#ComponentRestrictions