Reputation: 8935
I am using ionic 2 (beta11) and Google maps. I have a page that works fine, and it displays the map as expected.
To access this page, I click on an item and the page is loaded via this.nav.push(MapPage, {
. As you can see the map loads:
However, when I go up another level, and do this.nav.push(MapPage, {
again (displaying the same page), the page is displayed, but the map looks like this:
So it has navigated from one page to the same page, but the second time the map is not visible.
Here is my code:
html
<ion-card id="map" class="job-map"></ion-card>
map.ts
load(bounds: google.maps.LatLngBounds): void {
let mapOptions = {
center: bounds.getCenter(),
zoom: 15,
maxZoom: 15,
minZoom: 1,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var htmlElement: HTMLElement = document.getElementById("map");
this.map = new google.maps.Map(htmlElement, mapOptions);
this.map.fitBounds(bounds);
this.ref.markForCheck();
this.mapLoading = false;
}
If anyone can offer any suggestions, I would appreciate it.
Upvotes: 2
Views: 339
Reputation: 8935
The problem was because there were two pages on the stack with the same element id of "map". If I give each page a unique id, it works.
Upvotes: 2