如何延迟谷歌自动完成功能以节省信用 [英] How to delay the google autoComplete function to save credit

查看:19
本文介绍了如何延迟谷歌自动完成功能以节省信用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知,每次我们输入google map autoComplete都会触发,我想为此设置一个延迟功能,例如250ms,以便给用户更多时间输入并保存积分.我尝试添加 $timeout,但看起来它对我不起作用.你能帮我看看这个吗?先谢谢了.html:

As you know every time when we type the google map autoComplete will fire, I want to set a delay function for this, such as 250ms,so give user more time to type and also save the credits. I try to add $timeout, but looks like it didn't work for me. Would you please take look at this for me? Thanks advance. Html:

<input name="google_places_ac" type="text" class="google_places_ac input-block-level" ng-model="address" placeholder="Please enter a location" ng-blur="updateMap()"/>

指令:

 link: function($scope, elm, attrs) {  

                    $timeout(function(){

                    var autocomplete = new google.maps.places.Autocomplete($(elm).find(".google_places_ac")[0], {});  
                    google.maps.event.addListener(autocomplete, 'place_changed', function() {
                             var place = autocomplete.getPlace();
                            $scope.address = place.formatted_address;
                            $scope.location = {
                                formatted_address: place.formatted_address,
                                loglat: place.geometry.location
                            };
                            $scope.$apply();
                            //pop up the event and index(if needed)
                            $scope.$emit('updatemap',$scope.indexposition);
                        });
                    },1000);
}

每次我尝试输入搜索输入时,它都会立即弹出搜索结果列表,有什么办法可以延迟吗?以便用户可以输入更多字符?

every time I try to type in the search input, it will immediately popup the search result list, is there way I can delay it? so user can type more characters?

推荐答案

目前您无法通过 Maps JavaScript API 控制 Autocomplete 元素的地点预测请求频率.

Currently you cannot control the frequency of places prediction requests of Autocomplete element via Maps JavaScript API.

但是,公共问题跟踪器中有一个功能请求:

However, there is a feature request in the public issue tracker:

https://code.google.com/p/gmaps-api-issues/issues/detail?id=5831

Google 将此功能请求标记为已接受.我可以建议为此功能请求加星标,以表明您的兴趣并从 Google 获取进一步更新.

Google marked this feature request as Accepted. I can suggest starring this feature request to show your interest and get further updates from Google.

这篇关于如何延迟谷歌自动完成功能以节省信用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆