Google maps TypeScript error: Cannot find name 'google' - discussion

for persons like me that forget everything like me: do step 1,2 and 3 of @user2662006 answer in flowing link .

1 Like

How to do the step 3 ?

1 Like

Just type
declare module ‘googlemaps’;
into your declarations.d.ts

2 Likes

You are a savior! it works

Thanks, worked perfectly for me!

I found same same error Cannot find name ‘google’

I follow same steps but error still persists.

Please look into this. I stuck in this from long time.

Just declare var google:any;

next to imports on Angular 4 or 2 component.

Happy Day Coding.

Or just install the typings by running

npm install @types/google-maps --save

1 Like

it worked for me thank you so much :+1:

i got new error after i followed all replies:

iCannot read property ‘Autocomplete’ of undefined

I am not using a native google map but even with Javascript api I faced the same issue which by first installing the types with

npm install @types/google-maps --save

and then including following two lines

import { google } from "google-maps";

declare var google : google;
9 Likes

Just add

declare var google;

after import in your component diles.

It works! Thank you so much!

as an alternative you can just use this guys setup.

It runs in browser, devapp, ionic view. etc…

https://github.com/ng2-ui/map#usage

Hey there! I have the Elite version of this app and getting a similar error (See screenshot)


followed all of the suggestions above, but nothing seems to work. Any other suggestions?! :confused:

This might help:
Ionic Framework: ^3.9.2
Ionic App Scripts: 3.1.8
Angular Core: 5.0.1
Angular Compiler CLI: 5.0.1
Node: 6.10.0
OS Platform: Windows 10
Navigator Platform: Win32
User Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/64.0.3282.167 Safari/537.36

Try the following in your project:

npm install @types/googlemaps --save
npm install typings --global
typings install dt~google.maps --global

Yes I did. also had the line

with my API key.
still same issue.
Noticed an error on my index.d.ts, Map class, but might just be my ide… (see screenshot)


Any other suggestions?

In case this helps anyone, with @itaionic we discover that the fix is:

Install google-maps lib:

npm install google-maps --save

then in your Typescript file add:

import { google } from "google-maps";

And also define the following property:

google: google;

5 Likes

Finally this works for me. Thanks a lot!

Thank you! this works for me.