gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 11:47:16 24 4
gpt4 key购买 nike

使用 Angular 谷歌地图 (AGM),我试图在点击 map 时添加一个新标记。为此,我添加了一个事件 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

    最佳答案

    这是一个 bug在最新发布的版本中。 3.0.0-beta.0它显然已修复但未发布。
    您可以回复到 ^1.1.0 .
    或实现 workaround suggested in the issue .

    关于Angular Google Maps mapClick() 事件不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63817053/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com