您好,我正在尝试在我的 Angular 项目中实现谷歌地图,地图显示正常,但我添加了一个函数来在用户单击地图时获取纬度和经度,但我不断收到无法读取错误
应用程序组件:
export class AppComponent {
title = 'PI';
latitude = 51.678418;
longitude = 7.809007;
locationChosen = false;
onChoseLocation(event) {
this.latitude = event.coords.lat;
this.longitude = event.coords.lng;
this.locationChosen = true;}
}
HTML:
<agm-map [latitude]="latitude" [longitude]="longitude" (click)="onChoseLocation($event)">
<agm-marker [latitude]="latitude" [longitude]="longitude" *ngIf="locationChosen"></agm-marker>
</agm-map>
您尝试过“mapClick”输出吗? 我在文档“https://angular-maps.com/api-docs/agm-core/components/agmmap#source”中看到这一点