我正在使用gmap自动填充功能,有时用户在建议列表中没有任何选择。例如,他在输入字段中键入“Paris”并认为搜索将使用Paris执行,但是从未调用过gmap autcomplete的“place_changed”,搜索无法执行。 当用户没有做出任何选择时,如何默认选择建议列表的第一选择?我相信我可以使用模糊事件处理来调整为此处描述的“输入问题”(Google maps Places API V3 autocomplete - select first option on enter)提供的解决方案,但这不起作用。
任何提示?
答案 0 :(得分:3)
我认为这有点打败了自动完成的目的。
您可以像以下那样以编程方式检索自动填充预测:
function initialize()
{
var service = new google.maps.places.AutocompleteService();
service.getQueryPredictions({ input: 'some address' }, callback);
}
function callback(predictions, status)
{
if (status != google.maps.places.PlacesServiceStatus.OK)
{
alert(status);
return;
}
// Take the first result
var result = predictions[0]
// do as you wish with the result
}
希望有所帮助