仅从 Google Maps API 获取要自动完成的国家/地区 [英] Get only countries to autocomplete from Google Maps API
问题描述
我正在使用 Google Maps API 获取城市和国家/地区的自动完成列表(没有其他详细信息),并且效果很好.
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);
现在我想做完全相同的事情,但只获取国家/地区名称.类似于将 types: ['(cities)']
替换为 types: ['(countries)']
...
(我试过但没有用)
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?
推荐答案
没有快速的解决方案,因为 Google 只提供两种类型的集合:['(cities)'] 和 ['(regions)']
There is no quick solution as Google only offers two type collections: ['(cities)'] and ['(regions)']
没有可用的 ['(countries)'].
There is no ['(countries)'] available.
此处的文档:https://developers.google.com/places/documentation/autocomplete#place_types
您也可以使用来自以下网址的自动完成插件:http://www.geognos.com/api/en/countries/info/all.json
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屋!