ngAfterViewInit() {
this.getPlaceAutocomplete();
}
private getPlaceAutocomplete() {
const autocomplete = new google.maps.places.Autocomplete(this.addresstext.nativeElement,//输入东西提示的dom
{
componentRestrictions: { country: 'US' },
});
google.maps.event.addListener(autocomplete, 'place_changed', () => {
console.log(this.addresstext.nativeElement);
const place = autocomplete.getPlace();
this.invokeEvent(place);
});
}
invokeEvent(place: google.maps.places.PlaceResult) {
console.log(place);
this.ngZone.run(() => {
this.name = place.formatted_address;
this.search()
});
}