无法读取未定义的属性(读取“纬度”)

问题描述 投票:0回答:1

您好,我正在尝试在我的 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>
angular maps
1个回答
0
投票

您尝试过“mapClick”输出吗? 我在文档“https://angular-maps.com/api-docs/agm-core/components/agmmap#source”中看到这一点

© www.soinside.com 2019 - 2024. All rights reserved.