自动完成地址输入

时间:2016-12-05 10:54:27

标签: javascript google-maps

我正在使用Google自动完整地址搜索脚本。

因此,当用户输入地址时,输入会自动弹出搜索结果。目前,这显示了整个单词的地址,但我只需要英国地址

    public IEnumerable<ListItem> AllTextEntries {
    get
    {
        var items = new List<ListItem>
            {
                new ListItem() {Id = 1, Name = "Text1"},
                new ListItem() {Id = 2, Name = "Text2"},
                new ListItem() {Id = 3, Name = "Text3"}
            };
        return items;
    }
}

有没有办法将此限制在英国?

1 个答案:

答案 0 :(得分:1)

尝试更改此功能,唯一的变化是您通过添加组件限制传递给自动填充的选项

function initAutocomplete() {
    // Create the autocomplete object, restricting the search to geographical
    // location types.
    autocomplete = new google.maps.places.Autocomplete(
        /** @type {!HTMLInputElement} */(document.getElementById('autocomplete')),
        {
        types: ['geocode'],
        componentRestrictions: { country: "uk" }
    });

    // When the user selects an address from the dropdown, populate the address
    // fields in the form.
    autocomplete.addListener('place_changed', fillInAddress);
}