2

我正在使用谷歌地图 APIv3 AutocompleteService 将数据提取到引导程序的预输入。但是,与使用谷歌内置的自动完成返回的结果相比,结果有点不准确。

我的 HTML 代码:

<label>Built-in</label><input type="text" id="address1" />
<label>Customize</label><input type="text" id="address2" />

我的脚本:

<script>
    //this input use google built-in autocomplete
    var input1 = document.getElementById('address1');
    autocomplete = new google.maps.places.Autocomplete(input1);

    //this input use google AutocompleteService
    $('#address2').typeahead({
        source: process_keyword
    });

    var service = new google.maps.places.AutocompleteService();

    function process_keyword(query, process) {
        var place_results = [];
        var request = {
            input: query,
            types: ['geocode']
        };
        service.getPlacePredictions(request, function (predictions, status) {
            process($.map(predictions, function (prediction) {
                return prediction.description;
            }));
        });
    }
</script>

我在这里发布了完整的代码:http: //jsbin.com/ididas/1/edit

例如当我输入

9 亭天晃

到第一个框,它将显示 5 个结果。但是当我在第二个框中输入相同的查询时,它只会显示 2 个结果。

我的问题是为什么他们有这个不同,我该如何修复,以便我的自定义预输入完美地作为内置的自动完成功能

4

1 回答 1

3

对我来说,service.getPlacePredictions()也返回 5 个结果。问题出现在 中$.typeahead,因为当您搜索9 dinh tien hoang并且服务返回9 Đinh Tiên Hoàng查询字符串与结果不匹配时(例如,搜索d与 a 不匹配Đ,它是一个完全不同的字符)。

由于您根本不需要任何过滤$.typeahead()(因为 autocompleteService 已经返回过滤结果),您可以将其添加到 $.typeahead-options 中:

matcher:function(){return true;}
于 2013-03-20T07:26:21.607 回答