Angular2 Cannot find namespace ‘google’

Angular 6 & 7 steps (should also work for every other Angular version):

  1. npm install @types/googlemaps --save-dev
  2. Add googlemaps to the types array in both filestsconfig.app.json respectively in tsconfig.spec.json (save both files)
  3. At the top of your controller.ts
/// <reference types="@types/googlemaps" />
  1. 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);
});

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)