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'
I solved it by installing:
$npm install @types/googlemaps --save-dev
To expand on the answer from @suraj, you should have:
declare var google;
outside of the class you are trying to use it in.
Just like in the Josh Morony video, I put it beneath the imports but before the class declaration and annotations (@Injectable()
and so forth). I suppose it would still work if you put it above the imports or beneath the end of the class (and still outside of the class), if you were so inclined for whatever reason.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With