【问题标题】:Angular Google Maps mapClick() event not workingAngular Google Maps mapClick() 事件不起作用
【发布时间】:2020-09-09 17:55:19
【问题描述】:

使用 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>
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}`);
  }
}

问题

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

enter image description here

【问题讨论】:

  • 你安装的是什么版本?检查 package.json。
  • 我安装了以下版本:“@agm/core”:“^3.0.0-beta.0”和“@types/googlemaps”:“^3.39.13”@hyperdrive跨度>
  • @hyperdrive 我需要另一个不同的版本吗?

标签: angular maps marker


【解决方案1】:

这是最新发布版本中的bug3.0.0-beta.0

显然已修复但未发布。

您可以恢复为^1.1.0

或者实现workaround suggested in the issue

【讨论】:

  • 这就是问题所在。我已将版本更改为 1.1.0 并且知道它可以工作。谢谢! @hyperdrive
猜你喜欢
  • 2021-04-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多