I'm using Google Maps API to get autocomplete list of cities and countries (without other details), and it works exellent.
var input = document.getElementById('newAddress');
var options = {
types: ['(cities)']
};
autocomplete = new google.maps.places.Autocomplete(input, options);
Now I want to do exactly the same but to get only countries names. Somthing like replacing types: ['(cities)']
with types: ['(countries)']
...
(what I tried but didn't work)
What should I do in order to get only countries into my autocomplete?
I've been playing around with the Google Autocomplete API for a bit and here's the best solution I could find for limiting your results to only countries:
If you look at the result object that's returned, you'll see that there's an address_components array which will contain several objects representing different parts of an address. Within each of these objects, it will contain a 'types' array and within this 'types' array, you'll see the different labels associated with an address, including one for country.
There is no quick solution as Google only offers two type collections: ['(cities)'] and ['(regions)']
There is no ['(countries)'] available.
Documentation here: https://developers.google.com/places/documentation/autocomplete#place_types
EDIT:
You could as an alternative use an autocomplete plugin sourced from this url: http://www.geognos.com/api/en/countries/info/all.json