Sunday, June 2, 2024
 Popular · Latest · Hot · Upcoming
32
rated 0 times [  33] [ 1]  / answers: 1 / hits: 13621  / 11 Years ago, mon, february 10, 2014, 12:00:00

I have the following code which I've been manipulating for a while, but I simply can't get it to return results..






    <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 options = {
types: ['(cities)'],
componentRestrictions: {country: us}
};
var input = document.getElementById('searchTextField');
var autocomplete = new google.maps.places.Autocomplete(input , options);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>

</head>
<body>
<div class = row>
<input id=searchTextField type=text size=50 placeholder=Enter a location autocomplete=on>
</div>
</body>




Using the above code i am able to get the cities list for a specific Country. But my requirement is I need to get the Countries list alone.



If the options is not passed then all the Places are returned as Result.



Is there any way to filter the countries alone ??? Please help me if you have any solution for this.


More From » google-maps

 Answers
15

At this point, you can't as there is no 'country' place type. Regions will autocomplete countries though (but not countries alone).



    var options = {
types: ['(regions)']
};


Get only countries to autocomplete from Google Maps API offers some alternative solutions. Here's an example of regions alone: http://plnkr.co/edit/QjPEczt6AosghVP8EHNV


[#47897] Saturday, February 8, 2014, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bryantc

Total Points: 455
Total Questions: 96
Total Answers: 110

Location: San Marino
Member since Thu, Jun 30, 2022
2 Years ago
bryantc questions
Fri, Aug 13, 21, 00:00, 3 Years ago
Tue, Mar 30, 21, 00:00, 3 Years ago
Fri, Jun 5, 20, 00:00, 4 Years ago
Wed, May 27, 20, 00:00, 4 Years ago
;