Kingsley Simon
Kingsley Simon

Reputation: 2210

Error: can't find symbol GoogleMaps ionic2

I want to use the google maps on ionic2. I have added the cordova-google-maps plugin to my project and in my project i did the following

import { GoogleMaps } from 'ionic-native'

export class ListPage {
  service = new google.maps.places.AutocompleteService();
  constructor (private googleMaps: GoogleMaps) {}
}

I however get two errors.

I get an error that there is no name google and also that there is no symbol GoogleMaps which makes me think why there wont be one in ionic-native. It seems there is only one available if it is @ionic-native/google-maps but i find that weird or is it how it has been set up for ionic2?

Also am i only allowed to do this service = new google.maps.places.AutocompleteService(); when i add the google maps script <script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places"></script> on index.html? I thought since i have added the google maps plugin from cordova, that i dont need to add the script anymore on index.html or i still have to do both?

Any explanation and help is appreciated.

Thanks

Upvotes: 1

Views: 493

Answers (1)

Raja Yogan
Raja Yogan

Reputation: 918

After adding the cordova-google-maps plugin to your app, you need to install the ionic-native wrapper using the below command.

npm install @ionic-native/google-maps

Then import GoogleMaps in your app.module.ts and add it as a provider as well.

Detailed and simple instructions are given here - http://tphangout.com/ionic-2-google-maps/

Hope this helps you. Thanks.

Upvotes: 1

Related Questions