【发布时间】:2016-12-28 15:10:15
【问题描述】:
我有以下AutocompleteService() 的代码:
var strAddr = '';
if (address.value != "") {
var service = new google.maps.places.AutocompleteService();
service.getQueryPredictions({ input: address.value }, function (predictions, status) {
console.log('1');
if (status == google.maps.places.PlacesServiceStatus.OK) {
console.log('Original Response: ' + predictions[0].structured_formatting.secondary_text);
strAddr = predictions[0].structured_formatting.secondary_text;
}
});
console.log('strAddr: ' + strAddr);
console.log('2');
}
console.log('3');
我在控制台中收到如下响应:
- strAddr:
- 2
- 3
- 1
- 原始响应://在此处获取匹配的地址
但应该是:
- 1
- 原始响应://此处匹配地址>
- strAddr: //这里匹配的地址
- 2
- 3
为什么回调没有按预期顺序执行?
【问题讨论】:
标签: google-maps google-maps-api-3 google-places-api