好的,所以我构建了一个工作(几乎)地理编码器,它接受地址或纬度/经度组合,并建议结果见此处:
$(this).autocomplete({
source:function (request, response) {
if (geocoder == null) {
geocoder = new google.maps.Geocoder();
}
geocoder.geocode({'address':request.term }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var searchLoc = results[0].geometry.location;
var lat = results[0].geometry.location.lat();
var lng = results[0].geometry.location.lng();
var latlng = new google.maps.LatLng(lat, lng);
var bounds = results[0].geometry.bounds;
geocoder.geocode({'latLng':latlng}, function (results1, status1) {
if (status1 == google.maps.GeocoderStatus.OK) {
if (results1[1]) {
response($.map(results1, function (loc) {
return {
label:loc.formatted_address,
lat:lat,
lng:lng,
value:loc.formatted_address,
bounds:loc.geometry.bounds
}
}));
}
}
});
}
});
},
并且 90% 的时间它都非常有效。但是,我现在注意到有时它在弹出列表中返回的第一项是不可点击的。我已经为变量设置了日志,status
并注意到它偶尔是ZERO_RESULT
或QUERY_LIMIT_REACHED
。在这两种情况下,列表都会加载值,并且列表中的所有内容都是可选的,除了第一个。任何可能的解决方案的想法?