Google places api error in ionic

I am using google places api in ionic app.I places google places api script in index.html. The app allow the user to access wifi within specific place. User get internet access after login with our app. When application launch and user is connecting with our network, user do not have access to the internet. So i get error:

Application Error connection to the server was unsuccessful.

Is there anyway to call the google places api after user has access to the internet to avoid the error?

You can try adding async defer

<script async defer src="googleapis.com...etc"></script>

I already try it, but the in this case i get error: google is undefined

in your component, are you declaring var google?
i.e,

import { Component } from 'xxx';
declare var google;

@Component({
selector: 'xx',
templateUrl: 'xx'
})
export class MapPage {
}

Yes, i did. i declare var google.

hmm. I’m in the process of moving the next couple days, but when I get a chance after that I’ll post the entirety of my code for you, either here or i’ll get you the link to my git repository. It’s fully operational.

When application launch and user is connecting with our network, user do not have access to the internet. So i get error. Do you know how to tackle this situation?

It may be an issue of activating your service worker in index.html. But, that’s out of my league. I don’t know a whole lot about that subject, sorry.

This issue has been solved. The link to the answer is given below: