Skip to content
This repository has been archived by the owner on May 11, 2020. It is now read-only.

google is not defined #506

Closed
rogyvojevic opened this issue Feb 4, 2016 · 11 comments
Closed

google is not defined #506

rogyvojevic opened this issue Feb 4, 2016 · 11 comments

Comments

@rogyvojevic
Copy link

I'm working on hybrid app using cordova, I've included your library in my project but there is one problem. Because this will be app for mobile it does not require internet connection, it can work without it, but the problem is when I got no internet connection ng-maps is firing error:

google_is_not_defined

And it all would be fine, and I wouldn't be here if I can ignore it, but I can't. Angular is not finishing all bindings when that error fires up, so I get a lot of stuff inside double curly braces.

Error is fired up when I inject ng-maps inside a controller.

Is there any way you can make some kind of try/catch block when trying to access google variable

@allenhwkim
Copy link
Owner

Please try map-lazy-load if google map js cannot be preloaded.. Here is the example,
http://ngmap.github.io/#/!map-lazy-load-params.html

@Eralph
Copy link

Eralph commented Feb 6, 2016

i have faced this issue before...and if i remember it correctly, it has something to do with how you added the script for google map...what i did was remove the http from the url

<script type="text/javascript" src="//maps.google.com/maps/api/js"></script>

i faced this problem when trying to create an example in plunker..hope this can help

@rogyvojevic
Copy link
Author

Sorry guys, but nothing that you suggested really helps. Problem is inside ng-map.js itselft. When I inject NgMap inside my controller ng-map.js gets executed, as I understand, and like my error says, google variable is not defined, and it's not defined because there is no internet connection to get it.

@morphonet
Copy link

Hi all,

I had the same problem, map-lazy-load worked for me!

Thanks allenhwkim 👍

@m98
Copy link

m98 commented Sep 13, 2016

But the problem is inside ng-map.js

I don't know why lazy-load added some CSS resources to my page, which add scrolls to my page! I wanted to use (and text) simple map, without lazy load and it returned an errorgoogle is not defined

@Jasman
Copy link

Jasman commented Oct 8, 2016

simple trick.

ngcontroller:

if(typeof google == "undefined"){
    $rootScope.mapEnable = false;
}else{
    $rootScope.mapEnable = true;
}

html

<div ng-if="mapEnable" class="gmap_container" data-tap-disabled="true">
     <ng-map zoom="12" center="{{item.gmap}}"></ng-map>
</div>

@m98
Copy link

m98 commented Oct 8, 2016

Thanks @Jasman, but with your code, now my map is not shown at all! I wonder why does googleis not defined

@claudioviola
Copy link

Hi guys
I'm using lazy-init="true" but I 've always the issue and "google" is not defined.
If google is not defined I don't run "NgMap.initMap('my_map')" but I receive the error, is the same.

Do I have to use "map-lazy-load"? Is the only one way?
With "map-lazy-load" param If I enter many times in the view with my ng-map, how many times ngmap loads google maps api? This aspect is worry for me, I want to load once google maps

Thank you so much!

@ghost
Copy link

ghost commented Jan 15, 2017

I'm facing the same issue, left details on stackoverflow

@allenhwkim
Copy link
Owner

lazy-init for not showing map without a user intervention. For example, if you want to show hundreds of maps in a single page, but do not want to initialize any one of map until you an image. It stands by to be initialized with user intervention, but still requires google object.

map-lazy-load loads google maps first, then compile the inner html. If google map is already loaded, it does not insert <script> tag again as you see here

@kaustavkarmakar2
Copy link

angular.js:14525 TypeError: Cannot read property 'PlacesService' of undefined
at Object.init (map.js:39)
at new (map.js:26)
at Object.instantiate (angular.js:5018)
at $controller (angular.js:10881)
at Object.link (angular-route.js:1214)
at angular.js:1346
at invokeLinkFn (angular.js:10426)
at nodeLinkFn (angular.js:9815)
at compositeLinkFn (angular.js:9055)
at publicLinkFn (angular.js:8920) "

"

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants