Issue
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".
Solution
It's a bug in the latest published version. 3.0.0-beta.0
It's apparently been fixed but not published.
You could revert to ^1.1.0
.
Or implement the workaround suggested in the issue.
Answered By - hyperdrive
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.