I'm trying to add a map to my Angular project. Using AGM to achieve that (https://github.com/SebastianM/angular-google-maps). My map is not showing up though...
app.module.ts:
@NgModule(<NgModule>{
declarations: [
AppComponent,
],
imports: [
BrowserModule,
OrderModule,
AngularFireModule.initializeApp(environment.firebase),
AngularFirestoreModule,
FormsModule,
MatTabsModule,
BrowserAnimationsModule,
MatTableModule,
MatFormFieldModule,
MatInputModule,
NoopAnimationsModule,
MatPaginatorModule,
MatSortModule,
MatButtonModule,
MatDialogModule,
MatCardModule,
MatSelectModule,
MatDatepickerModule,
MatNativeDateModule,
AgmCoreModule.forRoot({
apiKey: <APIKEY>
})
],
exports: [FilterPipe],
providers: [],
bootstrap: [AppComponent]
})
app.component.html:
<div>
<agm-map [latitude]="51.678418" [longitude]="7.809007" [zoom]="zoom" [disableDefaultUI]="false"
[zoomControl]="false">
<agm-marker [latitude]="51.678418" [longitude]="7.809007"></agm-marker>
</agm-map>
</div>
I'm showing this in a mat-tab component (angular material)
Thanks in advance!
You're supposed to give the map a height so in your component styles add this:
agm-map{
height: 300px
}
This works for me:
In HTML
<agm-map [latitude]="lat" [longitude]="lng" [zoom]="zoom" [styles]="styles" [mapTypeId]='mapType' #AgmMap></agm-map>
in TS
ngAfterViewInit(): void {
setTimeout(() => {
console.log('Resizing');
this.agmMap.triggerResize();
}, 100);
}
In CSS
agm-map {
height: 300px !important;
width: 100%; /* This is really important*/
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With