I'm trying to create multiple markers in a Google Map with the AGM package. While I can create multiple markers hardcoding the latitude and longitude if I try to create them with data fetched from an API I can't make it work.
If I do a ngFor in a 'p' tag to show the latitude and longitude, it shows the data correctly but for some reason, it can't create the agm-markers. This is my code:
component.ts
gps_lats: Array<number>;
gps_longs: Array<number>;
constructor(private _api: ApiService) { }
ngOnInit() {
this._api.machinesLocation().subscribe(res => {
this.gps_lats = Object.values(res['data']).map(({ lat }) => lat);
this.gps_longs = Object.values(res['data']).map(({ long }) => long);
});
}
component.html
<div class="card ">
<agm-map [latitude]="39.9" [longitude]="-0.16">
<agm-marker *ngFor="let machine of gps_lats; index as i" [latitude]="gps_lats[i]" [longitude]="gps_longs[i]">
</agm-marker>
</agm-map>
</div>
machinesLocationservice