【发布时间】:2023-03-15 14:09:01
【问题描述】:
我正在尝试为 google 地方自动完成实现自定义 UI,因为预建的 UI 不允许我手动选择结果。在 getPlacePredictions 函数选项中不使用多种类型时,一切正常,但是当我使用 ['(regions)', '(cities)'] 时,状态返回 'invalid request'
是我做错了什么还是不能返回多种类型?
var _this = this;
this.input = $('#zipcode_autocomplete');
this.service = new google.maps.places.AutocompleteService();
this.input.on('input', function() {
return _this.service.getPlacePredictions({
input: _this.input.val(),
types: ['(regions)', '(cities)'],
componentRestrictions: {
country: 'us'
}
}, _this.callback);
});
this.callback = function(predictions, status) {
var i, prediction, _results;
console.log(predictions);
if (status !== google.maps.places.PlacesServiceStatus.OK) {
alert(status);
return;
}
i = 0;
prediction = void 0;
this.results = $('ul.location_results').removeClass('hidden').html('');
_results = [];
while (prediction = predictions[i]) {
this.results.append("<li><span class='location-address'>" + prediction.terms[0].value + "</span><span class='location-state'>" + prediction.terms[prediction.terms.length - 2].value + "</span></li>");
_results.push(i++);
}
return _results;
};
【问题讨论】:
-
好的,这很令人沮丧,感谢您将我指向该页面,我无法在任何地方找到它。 @Andy 如果您想将其发布为答案,我会接受它
-
完成。在那里也添加了更多信息。
标签: javascript jquery google-maps google-maps-api-3