Typescript Error Cannot find name 'google' in ionic2 when using googlemaps javascript API

YD_ picture YD_ · Feb 11, 2017 · Viewed 23.5k times · Source

I am following Joshua Morony's Getting Started with Google Maps in Ionic 2 video tutorial. I want to use google maps in my application and i end up with a typescript error. this is a part of the pages/home/home.ts file

initMap(){
let latLng= new google.maps.LatLng(6.929848, 79.857407);

let mapOpt={
  center : latLng,
  zoom : 15,
  mapTypeId :google.maps.MapTypeId.ROADMAP
};

this.map= new google.maps.Map(this.mapElement.nativeElement,mapOpt);}

I tried npm install --save @types/googlemaps,

but it still gives me the same typescript error Typescript Error Cannot find name 'google'

Answer

Biranchi picture Biranchi · Jun 7, 2017

I solved it by installing:

$npm install @types/googlemaps --save-dev