Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google maps only load the first time, second time it is gray

I have created an Ionic 2 / Angular 2 App. I have integrated Google Maps and it works fine. However the second time the Google Maps appears completely gray. I have searched the internet and tried different solutions to solve it. However, none of the solutions below work: - google.maps.event.trigger(this.map, 'resize'); - google.maps.event.clearInstanceListeners / this.map.detach(); / this.marker.setMap(null);

When I resize the view in chrome then the maps which appeared in gray is suddenly shown. So how can I trigger this resize manually. I hope you can help.

My code can be found here https://github.com/marinusgeuze/metjekindnaarbuiten.

Best regards, Marinus Geuze

===========================================

Issue is solved by adding next line of code: setTimeout(() => google.maps.event.trigger(this.map, 'resize'), 600);

like image 437
Marinus Geuze Avatar asked Sep 19 '16 19:09

Marinus Geuze


People also ask

Why does Google Maps go grey?

Sometimes when you scroll across a Google Map screen you'll see blocks of grey. Usually this occurs when the map is set to satellite view and the application struggles to load the data fast enough. However, sometimes this phenomenon occurs in map view if Google doesn't have access to the right data.

Why is my Google Maps not loading anything?

Clear the app's cache & data On your Android phone or tablet, open the Settings app . Tap Apps & notifications. Follow the steps on your device to find the Maps app. After you select the app, storage & cache options should be available.

What does grey on a map mean?

Google Maps. Green – Vegetation, darker shades mean more dense. Tan – Sand & scrub, lighter shades mean less vegetation. White – Void of any vegetation, sand dunes, mountain peaks. Light Gray – Population areas, cities, suburbs.

What is the gray color on Google Maps?

Contour lines overlaid on the map show elevation and gray numbers show altitude.


2 Answers

I didn't have exactly the same issue, but something similar happen when using LeafletJS in my Ionic 2 app, and a call to their invalidateSize function on a small timeout fixed the issue for my app. Here's an example:

ionViewLoaded() {
    console.log('ObservationDetails.ionViewLoaded');

    // Leaflet setup calls here
    ...

    // invalidateSize must be called because the page hasn't been drawn, only loaded,
    // and the map div will get resized causing the "gray block/unloaded map tile"
    // problem. Invalidating the map will fix that, but the call needs a slight 
    // delay before firing...
    setTimeout(() => this.map.invalidateSize(), 600);
}
like image 72
sherb Avatar answered Sep 28 '22 15:09

sherb


Solution for map, Use Below code of line to resolve the issue :

// you must use "map" variable name, or you can use your defined variable name
// Example : var map = (new google.maps.Map(...));

setTimeout(function() { google.maps.event.trigger(map, 'resize') }, 600);
like image 34
Irshad Khan Avatar answered Sep 28 '22 14:09

Irshad Khan