我一直试图添加谷歌地图自动完成在离子2项目更新用户的位置。但是,addEventListener似乎不工作,并没有控制台错误可以有谁告诉我我要去哪里?谷歌地图的地方自动完成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>
我尝试过,但仍然保持原样,但输入时没有显示下拉列表,但当我点击输入console.log('place_changed',this.location.loc)打印输入的值 – Idlliofrio
您是否将'function(){'更改为'()=>'? – yurzui
是的,我改变了它的箭头功能 – Idlliofrio