如何让谷歌自动完成只建议有邮政编码和门牌号的地方?我希望只能选择有邮政编码的房子。
我尝试过的:
const autocompleteConfig = {
componentRestrictions: { country: {{country}} },
types: ['address'],
};
const autocomplete = new google.maps.places.Autocomplete({{element}}, autocompleteConfig);
我得到的结果有问题 - 一些建议没有邮政编码或门牌号。
最佳答案
应该使用 google places 服务。
const autocomplete = new google.maps.places.Autocomplete(this.searchElementRef.nativeElement);
const placesService = new google.maps.places.PlacesService(this.searchElementRef.nativeElement);
首先获取自动完成预测:
placesService.getPlacePredictions({input: 'your place string'})
然后获取每个预测的地点 zip 和house_number
placesService.getDetails({placeId: placeIdFromPrediction})
然后过滤建议。
关于javascript - 如何过滤谷歌地方自动完成建议?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55043515/