簡體   English   中英

如何過濾谷歌地點自動完成建議?

[英]How to filter google places autocomplete suggestions?

如何讓谷歌自動完成只建議有郵政編碼和門牌號的地方? 我希望只能選擇帶有郵政編碼的房子。

我試過的:

const autocompleteConfig = {
    componentRestrictions: { country: {{country}} },
    types: ['address'],
};

const autocomplete = new google.maps.places.Autocomplete({{element}}, autocompleteConfig);

我得到的結果的問題 - 有些建議沒有郵政編碼或門牌號。

應該使用谷歌地點服務。

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})

然后過濾建議。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM