You should use a Service to load the Maps API.
See:
- https://stackoverflow.com/questions/34931771/how-to-load-google-maps-api-asynchronously-in-angular2
- https://github.com/SebastianM/angular-google-maps/blob/master/packages/core/services/maps-api-loader/lazy-maps-api-loader.ts
Also see:
For example:
import {} from '@types/googlemaps';
...
public ngOnInit() {
this.mapsApiLoaderService.load().then(res => {
this.loadMap();
});
}
private loadMap() {
const opts: google.maps.MapOptions = {
...
center: new google.maps.LatLng(this.currentPosition.latitude, this.currentPosition.longitude),
...
};
...
}