Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

google is not defined #1504

Closed
lespons opened this issue Sep 24, 2018 · 5 comments · Fixed by #1506
Closed

google is not defined #1504

lespons opened this issue Sep 24, 2018 · 5 comments · Fixed by #1506

Comments

@lespons
Copy link

lespons commented Sep 24, 2018

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
@Smiter15
Copy link

Smiter15 commented Sep 24, 2018

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

@Smiter15
Copy link

Smiter15 commented Sep 24, 2018

I don't think this is an issue anymore, I just had to do some minor refactoring as this feature has now been merged:
#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

@sebholstein
Copy link
Owner

@lespons Please provide a demo on Stackblitz

@gionkunz
Copy link

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.

@fredgate
Copy link

fredgate commented Jan 15, 2019

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(); ?

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

Successfully merging a pull request may close this issue.

5 participants