2013-03-29 16 views
5

我正在使用gmap自動完成,有時用戶不會在建議列表中選擇任何選項。例如,他在輸入字段中輸入「Paris」,並認爲搜索將在巴黎執行,但gmap自動完成的'place_changed'從未被調用,搜索無法執行。 如何在用戶不做任何選擇時默認選擇建議列表的第一個選項?我相信我可以將爲此處所述的「輸入問題」(Google maps Places API V3 autocomplete - select first option on enter)提供的解決方案與模糊事件處理進行適配,但這不起作用。谷歌地圖自動完成在默認情況下選擇列表中的第一個條目

任何提示?

回答

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  
} 

希望幫助

+0

你是男人!它正在吹我的頭2天。 :)) 謝謝! – zur4ik

+0

非常歡迎 –

相關問題