作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
使用 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}`);
}
}
问题 :
最佳答案
这是一个 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/
每当我添加一个标记并计算 map 上的路线时,单击第二个标记,它会在单个图标上显示两个标记,如图所示。我只想在一个位置使用一个标记(即 A) 代码片段 var map, lat, lng; var c
使用 Angular 谷歌地图 (AGM),我试图在点击 map 时添加一个新标记。为此,我添加了一个事件 mapClick,它会将带有坐标的事件发送到 addMarker 方法。 import
我是一名优秀的程序员,十分优秀!