Angular 6 & 7 steps (should also work for every other Angular version):
npm install @types/googlemaps --save-dev- Add
googlemapsto the types array in both filestsconfig.app.jsonrespectively intsconfig.spec.json(save both files) - At the top of your controller.ts
/// <reference types="@types/googlemaps" />
- Restart npm server
The types array should look like these in both files
{
"compilerOptions": {
"types": ["googlemaps","othertype",...]
}
}
You can delete both declaration types from the components:
import {} from '@types/googlemaps';declare var google: any;You don’t have to include any of them.
PS: If you are using agm-s GoogleMapsAPIWrapper.getNativeMap() you must convert the map object before you use it. For example turning on the traffic layer:
this.apiWrapper.getNativeMap().then(map => {
this.trafficLayer = new google.maps.TrafficLayer();
const gMap: any = map;
this.trafficLayer.setMap(gMap as google.maps.Map);
});