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