只允许Google Maps API自动填充国家/地区 [英] Get only countries to autocomplete from Google Maps API
问题描述
我使用Google Maps API获取城市和国家/地区的自动填充列表(没有其他详细信息),并且它运作良好。
var input = document.getElementById('newAddress');
var options = {
types:['(cities)']
};
autocomplete = new google.maps.places.Autocomplete(input,options);
现在我想要完全相同,但仅获取国家/地区名称。类似于:使用类型替换
.. 。类型:['(cities)']
类型:['(countries)']
(我尝试过,但没有工作)
我应该怎么做才能让国家进入我的自动完成状态?
Google没有提供快速解决方案,只提供两种类型集合:['(cities)']和['(regions)']
没有['(countries)']可用。
文档在这里: https://developers.google.com/places/documentation/autocomplete#place_types
编辑: 您可以选择使用源自此网址的自动填充插件: http://www.geognos.com/api/en/countries/info/all .json
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?
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
这篇关于只允许Google Maps API自动填充国家/地区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!