使用 google place api 和 jQuery 自动完成
我正在使用 googleplaces 和 jquery 来实现一旦用户开始在输入字段中输入内容的目标,它就会调用 googleplaces 并在下拉列表中提供结果(通过 jquery ui 自动完成)
我的问题是,在我的自动完成中我在那里的函数
source: function( request, response ) {
initialize()
}
,我试图调用这个函数
function initialize() {
service.search(request, callback);
}
,它工作得很好...但问题是...初始化调用了函数callback()...所以我不知道如何听查看回调何时完成。
例如,我在这里会做什么:
source: function( request, response ) {
// need code here to know when initialize and callback are done and are sending me the list of results from google ?
}
在我使用结果中的 $.map 生成下拉列表之前,我只是不确定如何等待 googleplaces 完成。
I'm using google places and jquery to achieve the goal of once the user starts typing in an input field, it does a call to google places and feeds the results in a dropdown (via jquery ui autocomplete)
My problem is, in my autocomplete function I have
source: function( request, response ) {
initialize()
}
In there, I'm trying to call this function
function initialize() {
service.search(request, callback);
}
Which works fine... but the problem is... initialize does a call out to the function callback()... so I'm not sure how to listen to see when the callback is done.
So for example, what would I do here:
source: function( request, response ) {
// need code here to know when initialize and callback are done and are sending me the list of results from google ?
}
I'm just not sure how to wait for google places to get done, before I use $.map from the results to produce the dropdown.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
谷歌API的计时问题?我感受到你的痛苦。但为了回避您的问题并可能为您减轻一些痛苦,您可以使用 Google 的预构建解决方案:
http ://code.google.com/apis/maps/documentation/javascript/places.html#places_autocomplete
如果您出于某种原因不使用他们的 API,我们深表歉意。
Timing issues with google apis? I feel your pain. But to sidestep your issue and maybe save you some pain, you could use Google's prebuilt solution:
http://code.google.com/apis/maps/documentation/javascript/places.html#places_autocomplete
Apologies if you have some reason to not use their API.