【发布时间】:2017-11-13 11:14:17
【问题描述】:
我想显示来自谷歌自动完成预测的输入提示。
var service = new google.maps.places.AutocompleteService();
$('.delivery_areas').typeahead({
highlight: true,
minLength: 3,
},{
name: 'predictions',
limit: 6,
async: true,
source: function(q, sync,async) {
matches = [];
service.getPlacePredictions({
input: q
}, function(predictions, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
predictions.forEach(function(prediction) {
matches.push(prediction.description);
});
}
});
//console.log(matches) display a list of suggestions from google
async(matches);
//cb(matches) also wont work
}
});
不知何故,它不适用于来自自动完成 API 的结果。 我已经尝试过 sync 和 async 回调。
注意:Typeahead 与示例数据源一起正常工作,API 端也没有问题。结果即将到来并存储在匹配数组中。
【问题讨论】:
标签: javascript google-maps-api-3 typeahead.js