Angular-google-maps: google is not defined

Created on 24 Sep 2018  路  5Comments  路  Source: SebastianM/angular-google-maps

Issue description
I have undefined error in

const newBounds = google.maps.LatLngBounds();
https://github.com/SebastianM/angular-google-maps/blob/master/packages/core/directives/map.ts#L479

Steps to reproduce and a minimal demo of the problem

  • Set fitBounds
more info

Most helpful comment

I have a related issue but it is on extending the bounds.

https://github.com/SebastianM/angular-google-maps/blob/master/packages/core/directives/map.ts#L494

Only since updating to 1.0.0-beta.4

All 5 comments

I have a related issue but it is on extending the bounds.

https://github.com/SebastianM/angular-google-maps/blob/master/packages/core/directives/map.ts#L494

Only since updating to 1.0.0-beta.4

I don't think this is an issue anymore, I just had to do some minor refactoring as this feature has now been merged:
https://github.com/SebastianM/angular-google-maps/pull/1389

In your agm-map tag amend the fitBounds attribute to be true:
<agm-map (mapReady)="mapReady($event)" ... [fitBounds]="true" ...>

In your agm-marker tag add this attribute:
<agm-marker *ngFor="let marker of markers" ... [agmFitBounds]="true" ...>

Hope this helps

@lespons Please provide a demo on Stackblitz

I've just noticed that there's a problem with the fitBounds set to a bounds literal when using the lazy API loader. The problem is that the input change tiggers a update and the google namespace is not there yet. It would make sense to inject the loader in the map component and use the load function to resolve the returned promise before accessing the google namespace. This is actually valid for all locations where the google namespace is used at runtime.

I have a similar problem with the fitBoundsproperty. My compnent sets this property to false if the google maps library is not loaded. When the library is loaded, my component calculates the best bounds it needs and sets the fitBoundsproperty to a LatLngBoundsLiteral instance.
But there is is an exception in the _updateBounds function of the AgmMap compnent. The problem is located here :

if (this._isLatLngBoundsLiteral(bounds) && google && google.maps) {
    var newBounds = google.maps.LatLngBounds();
    newBounds.union(bounds);
    bounds = newBounds;
}

The google and google.maps namespaces are correctly defined. The google.maps.LatLngBounds function exist.
But the variable newBounds is set to undefined, so the next line newBounds.union(bounds)fails.
Why not have var newBounds = new google.maps.LatLngBounds(); ?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

gnujeremie picture gnujeremie  路  3Comments

Subhojit1992 picture Subhojit1992  路  3Comments

DeveloperAdd007 picture DeveloperAdd007  路  3Comments

maneesht picture maneesht  路  3Comments

supran2811 picture supran2811  路  4Comments