Get only countries to autocomplete from Google Maps API

Tags: , ,



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?

Answer

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



Source: stackoverflow