Integrating Google Maps into an Angular 15 application is a similar process as Angular 14. Here’s an example of how you can do it:
- Install the
@agm/core
package by running the following command in your terminal:
Copy codenpm install @agm/core
- Next, you need to import the
AgmCoreModule
in yourapp.module.ts
file and configure it with your Google Maps API key:
Copy codeimport { AgmCoreModule } from '@agm/core';
@NgModule({
imports: [
AgmCoreModule.forRoot({
apiKey: 'YOUR_API_KEY'
})
],
// ...
})
export class AppModule { }
- In the component where you want to display the map, import the
AgmMap
component and use it in your template:
Copy codeimport { Component } from '@angular/core';
@Component({
selector: 'app-map',
template: `
<agm-map [latitude]="lat" [longitude]="lng">
<agm-marker [latitude]="lat" [longitude]="lng"></agm-marker>
</agm-map>
`
})
export class MapComponent {
lat = 51.678418;
lng = 7.809007;
}
You can also customize the map by using various inputs andRegenerate response.