Using Angular Google Map (AGM), I'm trying to add a new marker when map is clicked. To do so, I have added an event mapClick that will send the event with the coordinates to addMarker method.
<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}`);
}
}
PROBLEM:
- CANNOT GET COORDINATES. Error in html = 'Identifier coords is not defined'
- When i print the event on console, returns "c".