1
我現在有一個地方自動完成,顯示一個國家的結果。 我想要做的是讓它顯示更多國家的結果(限於2或3)。填寫谷歌地圖自動填充與預測結果
據我所知,這是不可能的當前版本的自動完成(https://code.google.com/p/gmaps-api-issues/issues/detail?id=4233) 所以我要做的是得到兩個預測列表,並顯示它們而不是自動完成結果。
有沒有什麼辦法觸發自動填充的下拉部分,並用預測列表填充它?
在輸入的onChange觸發代碼:
var inputData = this.value;
var options = {
componentRestrictions: { country: "be" }
};
service = new google.maps.places.AutocompleteService();
var request = {
input: inputData,
componentRestrictions: {country: 'be'},
};
var secondaryRequest = {
input: inputData,
componentRestrictions: {country: 'lu'},
};
service.getPlacePredictions(request, callback);
service.getPlacePredictions(secondaryRequest, callback);
回調函數:
function callback(predictions, status) {
if (status != google.maps.places.PlacesServiceStatus.OK) {
alert(status);
return;
}
//here I need to display that dropdown if it isn't already
// and then add the results of the current predictions.
}
因此,我使用上面的代碼和自定義'彈出'div來顯示結果。如果任何人有更好的主意,我會將問題留待幾天。之後我會發布我的解決方案(因爲它需要一些清理)。 – 2014-11-06 08:19:59