如何解决Angular Google Maps mapClick事件不起作用
使用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 =“未定义标识符坐标”时发生错误
- 当我在控制台上打印 event 时,返回“ c”。
解决方法
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。