我正在使用Google地图自动完成功能来搜索地址,用户首先选择国家/地区,然后基于这些输入,我需要将搜索限制在该用户选择的特定城市。
ngAfterViewInit() {
this.getPlaceAutocomplete();
}
private getPlaceAutocomplete() {
this.autocomplete = new google.maps.places.Autocomplete(this.addresstext.nativeElement,
{
componentRestrictions: { country: 'RS' },
types: ['address'] // 'establishment' / 'address' / 'geocode'
});
google.maps.event.addListener(this.autocomplete, 'place_changed', () => {
const place = this.autocomplete.getPlace();
this.locationForm.get('adresa').setValue(place.name);
this.lat = place.geometry.location.lat();
this.lng = place.geometry.location.lng();
this.locationForm.get('coordinates').setValue([this.lng, this.lat]);
});
}