Angular-google-maps: Getting only a grey map with ionic2

Created on 21 Sep 2016  路  5Comments  路  Source: SebastianM/angular-google-maps

I'm using angular2-google-maps version 0.12.0 with ionic2 beta 11.

My code looks like this: http://plnkr.co/edit/IzcUBS4gCKDfGpb3TCvi?p=preview
I tried to post most of my code, but i dont know how to make the plunker code work.

And i am importing the all the necessary things.
I'm opening the component with navController.push().

The strange thing is that i just see a grey box with google control icons (like + and - for zoom).
But when i'm opening or closing the chrome developer tools, the correct view of map appears.

Is it a bug or am i doing something wrong?

Edit:
I can reproduce the behavior with native maps implementation. When i start the map, i can only see the grey map, but if i start it with setTimeout and a short wait time, the map is showed correctly. Any idea what the problem could be?

Edit2:
With the native map, i can show the map with google.maps.event.trigger(myMap, "resize");
Is there a possibility to do the same with angular-maps?

Most helpful comment

Yes, it's the default google-maps resize problem, I solved by using this.map.triggerResize() in the method ionViewDidLoad of my PageComponent, where you can reference your map (if you have just one in that page) with @ViewChild(SebmGoogleMap) map: SebmGoogleMap

All 5 comments

Yes, it's the default google-maps resize problem, I solved by using this.map.triggerResize() in the method ionViewDidLoad of my PageComponent, where you can reference your map (if you have just one in that page) with @ViewChild(SebmGoogleMap) map: SebmGoogleMap

@Jamby93 thx for the solution. This is right solution for the problem. Closing this as this is no bug.

this needs to be in docs
this.map.triggerResize() for lazy

Getting same issue. Thanks in advance
Component
import { AgmMap } from '@agm/core';

@ViewChild(AgmMap) map: AgmMap;

initialize() {

    //set google maps defaults
    this.zoom                       = 12;

    this.latitude                   = 12.9777688;

    this.longitude                  = 77.6345873;

}

openMapPopup() {
this.initialize();
this.map.triggerResize()
jQuery('#map-modal').modal('show');
}

Html



For those who are still struggling with this issue, Just FYI, calling this.map.triggerResize() inside a setTimeout function will make it work.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

shedar picture shedar  路  4Comments

mensch picture mensch  路  3Comments

Halynsky picture Halynsky  路  3Comments

n1t3w0lf picture n1t3w0lf  路  3Comments

ostapch picture ostapch  路  4Comments