Map Container is already initialized error in IONIC 2

//Munich
this.center = {lat: 28.7041, lng: 77.1025};

this.map = L.map('map', {
  center: this.center,
  zoom: 13,
  layers: [grayscale,streets, cities]
});

I am initialing openstreet map with leaflet in ionic 2. when i am loading the page again i am getting a crash i.e. map container is not initialized. it seems there is already some div present. I tried checking null also but the no success. friends please help.

Hi ashish1311,

I had the same problem 2 days ago. I don’t know if it’s the best way to fix it but I simply remove the map when the user leaves the view. Here is my code :

ionViewCanLeave(){
	document.getElementById("map").outerHTML = "";
}
4 Likes

Thank you very much…i was getting crazy bu this issue. This works.

ionDidLeave(){
document.getElementById(“map”).outerHTML = “”;
}

worked for me.