javascript - 如何过滤谷歌地方自动完成建议?

标签 javascript google-places-autocomplete

如何让谷歌自动完成只建议有邮政编码和门牌号的地方?我希望只能选择有邮政编码的房子。

我尝试过的:

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/

相关文章:

javascript - 为什么音频无法在 Safari 中播放并给出错误 '' undefined' is not a constructor (evaluating 'new Audio()' )'

java - 迁移到新 Places SDK 客户端 | E/计划策略 : set_timerslack_ns write failed: Operation not permitted

javascript - 如何在 React 项目中加载 Google Places JS API 库?

ios - Google 地方信息未加载到 TableView 中

javascript - 更新面板删除了 URL 片段

javascript - 使用 jquery 检测变量变化

java - 使用新的 Google Places SDK 使用 PlaceAutoCompleteFragment 时设置 Place Fields 错误

javascript - Jquery UI 脚本未加载

JavaScript 使 getContext() 公开?