Google지도를 자동으로 작성하여 이온 2 프로젝트에 추가하여 사용자 위치를 업데이트하려고했습니다. 그러나 addEventListener가 작동하지 않는 것으로 보이며 콘솔 오류가 발생할 수 있습니다. 아무도 내가 잘못 가고 있다고 말해?Google지도 장소 자동 완성 addEventListener가 작동하지 않습니다
ngAfterViewInit() {
let input = <HTMLInputElement> document.getElementById("auto");
console.log('input', input);
let options = {
componentRestrictions: {
country: 'IN',
types: ['(regions)']
}
}
let autoComplete = new google.maps.places.Autocomplete(input, options);
console.log('auto', autoComplete);
google.maps.event.addListener(autoComplete, 'place_changed', function() {
this.location.loc = autoComplete.getPlace();
console.log('place_changed', this.location.loc);
});
}
<ion-label stacked>Search Location</ion-label>
<input type="text" id="auto" placeholder="Enter Search Location" [(ngModel)]="location.loc" />
index.html을
<script src="https://maps.googleapis.com/maps/api/js?key=xxxxxxxxxxxxxx&libraries=places"></script>
autoComplete
에
place_changed
이벤트를 확인하여
드롭 다운 프로그램을 입력하지 않고도 시도했지만 console.log ('place_changed', this.location.loc)는 입력 된 값을 인쇄합니다. – Idlliofrio
'function() {'을'() =>'으로 변경 했습니까? – yurzui
예 화살표 기능으로 바 꾸었습니다. – Idlliofrio