Hi All,
I have an implementation using google maps js api. It works perfectly when I run it in a component
. However, I want it to display in a modal
. When I run it in a modal
, it gets no errors reported and the map
object seems to be created, the div
can be found, but it just does not render the map. The modal
is displayed, all the html renders, but the map is just not displayed.
My code is as follows:
filterMap.html
<ion-header> <ion-navbar> <ion-nav-items> <button (click)="addMarker()" danger>Add Marker <ion-icon class="ion-ios-pin"></ion-icon></button> <button (click)="undoLastMarker()" light>Undo <ion-icon class="ion-ios-undo"></ion-icon></button> <button (click)="deleteAllMarkers()" light>Clear <ion-icon class="ion-ios-trash"></ion-icon></button> </ion-nav-items> </ion-navbar> </ion-header>
<ion-content padding>
<div id="filterMap"></div>
</ion-content>
filterMap.ts (modal)
import { Component } from '@angular/core'; import { NavController, NavParams, Loading } from 'ionic-angular/index'; import { Geolocation } from 'ionic-native';
@Component({ templateUrl: 'build/pages/search/filterMap.html' }) export class FilterMapModal {
private map: any; private google: any; private markers = []; private loading: Loading = Loading.create();
constructor(private params: NavParams, private nav: NavController) { this.map = null; this.loadMap(); }
loadMap() { let options = { timeout: 10000, enableHighAccuracy: true };
Geolocation.getCurrentPosition(options).then((position) => { let latLng = new google.maps.LatLng(position.coords.latitude, position.coords.longitude);
let mapOptions = { center: latLng, zoom: 15, mapTypeId: google.maps.MapTypeId.ROADMAP };
this.map = new google.maps.Map(document.getElementById("filterMap"), mapOptions); console.log(this.map); console.log(document.getElementById("filterMap")); }); }
}
console output from the above code:
Object { gm_bindings_={...}, __gm={...}, gm_accessors_={...}, more...} <div id="filterMap">
search.ts (calls the modal)
presentModal() { let myModal = Modal.create(FilterMapModal, { param: "something" }); this.nav.present(myModal); }