Angular Google Maps mapClick() 事件不起作用

Alb*_*lez 6 maps marker angular

使用 Angular Google Map (AGM),我试图在点击地图时添加一个新标记。为此,我添加了一个事件mapClick,它会将带有坐标的事件发送到addMarker方法。

<agm-map [latitude]="location.latitude" [longitude]="location.longitude" (mapClick)="addMarker($event.coords.lat, $event.coords.lng)">
<agm-marker [latitude]="location.latitude" [longitude]="location.longitude"></agm-marker>
Run Code Online (Sandbox Code Playgroud)
import { Component, OnInit } from '@angular/core';

import { Location } from '../models/map-model';

@Component({
  selector: 'app-map',
  templateUrl: './map.component.html',
  styleUrls: ['./map.component.scss']
})
export class MapComponent implements OnInit {
  public location: Location;
  public markers: [];

  constructor() { /*empty*/ }

  ngOnInit(): void {
    this.location = {
      latitude: -28.68352,
      longitude: -147.20785
    }
  }

  addMarker(latitude: number, longitude: number) {
    console.log(`latitude: ${latitude}, longitude: ${longitude}`);
  }
}
Run Code Online (Sandbox Code Playgroud)

问题

  • 无法获得坐标。html 中的错误 = '标识符坐标未定义'
  • 当我在控制台上打印事件时,返回“c”。

在此处输入图片说明

hyp*_*ive 7

这是最新发布版本中的一个错误3.0.0-beta.0

它显然已修复但未发布。

你可以恢复到^1.1.0.

或实施问题中建议解决方法