question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[bug] BUG: Loading Map again crashes with message that map already exists.

See original GitHub issue

I’m submitting a … (check one with “x”) [ x ] bug report

If you choose ‘problem or bug report’, please select OS: (check one with “x”) [ x ] Android

cordova information: (run $> cordova plugin list)

cordova-plugin-compat 1.0.0 "Compat"
cordova-plugin-console 1.0.5 "Console"
cordova-plugin-device 1.1.4 "Device"
cordova-plugin-geolocation 2.4.3 "Geolocation"
cordova-plugin-googlemaps 2.1.1 "cordova-plugin-googlemaps"
cordova-plugin-inappbrowser 1.7.1 "InAppBrowser"
cordova-plugin-network-information 1.3.3 "Network Information"
cordova-plugin-request-location-accuracy 2.2.2 "Request Location Accuracy"
cordova-plugin-splashscreen 4.0.3 "Splashscreen"
cordova-plugin-statusbar 2.2.2 "StatusBar"
cordova-plugin-uniquedeviceid 1.3.2 "UniqueDeviceID"
cordova-plugin-whitelist 1.3.1 "Whitelist"
cordova-sqlite-storage 2.0.4 "Cordova sqlite storage plugin"
cordova.plugins.diagnostic 3.6.8 "Diagnostic"
ionic-plugin-keyboard 2.2.1 "Keyboard"
onesignal-cordova-plugin 2.2.1 "OneSignal Push Notifications"

If you use @ionic-native/google-maps, please tell the package.json (only @ionic-native/core and @ionic-native/google-maps are fine mostly)

 "@ionic-native/core": "^4.4.0",
 "@ionic-native/diagnostic": "^4.4.0",
 "@ionic-native/geolocation": "^4.4.0",
 "@ionic-native/google-maps": "^4.4.0",

Current behavior:

When loading map page from menu it crashes , with error message

console.error: GoogleMaps DIV[__pluginMapId='map_0_1171669735998'] has already map.

Expected behavior:

It should load map

Screen capture or video record:

capture

Related code, data or error log (please format your code or data):

Menu Item load map code

this.nav.setRoot(MainPage);

Variables

 map: GoogleMap;
 mapElement: HTMLElement;
 map_id = "map";

Code for creating map

 this.mapElement = document.getElementById(this.map_id);
      /*
      * @comment: Initial configuration for map pointing central brunch
      * */
      let mapOptions: GoogleMapOptions = {
        controls: {
          compass: false,
          myLocationButton: false,
          indoorPicker: false,
          mapToolbar: false
        },
        camera: {
          target: {
            lat: 40.1817318,
            lng: 44.5122556
          },
          zoom: 8
        },
        styles: [{
          stylers: [{
            saturation: -100
          }]
        }]
      };
      /*
      * @comment: Creating google map
      * */
      if (!this.map) {

        this.map = GoogleMaps.create(this.mapElement, mapOptions);
      }

Suggest

Create static method to destroy map object or resset

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:57 (27 by maintainers)

github_iconTop GitHub Comments

4reactions
wf9a5m75commented, Nov 17, 2017

Okay, I got the reason of GoogleMaps DIV[__pluginMapId='map_0_1171669735998'] has already map..

Because you write your code like this:

this.mapElement = document.getElementById('map-main-page');
if (!this.map) {
  this.map = GoogleMaps.create(this.mapElement, mapOptions);
}

The ionic framework uses fade-in and fade-out when you change the pages, even accessing to the same page. In your case, for changing language, the ionic regenerates new DOM tree.

So if there is the same div tag in pageA(Eng page) and pageB(Rus page), can you image what happens?

this.mapElement = document.getElementById('map-main-page');

This code returns the div of pageA, because it is still remained during the fading out. So the <div id="map-main-page"> is still remained, that’s why the plugin outputs the error GoogleMaps DIV[__pluginMapId='map_0_1171669735998'] has already map.. But very after, the element is removed. That’s why the plugin remove the map automatically. Then you get a blank page.


For the reason, I recommend to use this way for ionic users. https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.0.0/ReleaseNotes/ionic-googlemaps-4.3.3/README.md#update-specifying-element-id-for-mapcreate

if (!this.map) {
  this.map = GoogleMaps.create('map-main-page', mapOptions);
}

Since @ionic-native/google-maps@4.3.0, the wrapper plugin waits the specified ID element is loaded. This prevents this problem.

issue_1890

0reactions
mnatsakanyancommented, Dec 18, 2017

@wf9a5m75 any suggest?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Game crashes on map load :: Overgrowth General Discussions
Bring it up, click the window, and hit CTRL + C to copy it to your clipboard. Then CTRL + V in the...
Read more >
How to fix Maps when it crashes - Android - Google Maps Help
​​​​​​​Go to device Settings and then Apps. · Tap on Apps again. · Select Maps app. · Tap Storage and then Clear data....
Read more >
Game crashing when loading map - Bug reports
Now the actual problem: When I try to start a single player game, the game crashes while loading the map. Everything up to...
Read more >
My Maps Activity crashes as soon as it loads - Stack Overflow
Upon accessing the Maps Activity, it crashes. I've tried switching out the Activity with a generic Maps Activity which does work, and I've ......
Read more >
World War 3 Crashes After Loading Map? Try these fixes
Players playing World War 3 have been encountering an issue where the game crashes when the map loads for them. This may not...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found