Well, i’m trying to use the google maps and its not working properly, it only works in the rootPage but when i try to load the maps in a page that is not the root the ion content gets transparent and don’t show the map.
import {Page} from "ionic-angular";
import {OnInit, Component} from "@angular/core";
import {GoogleMap, GoogleMapsEvent} from "ionic-native";
@Component({
templateUrl: "build/pages/map/map.html"
})
export class MapPage {
constructor(private navCtrl: NavController) {
}
ngOnInit() {
setTimeout(() => {
let map = new GoogleMap('map');
map.on(GoogleMapsEvent.MAP_READY).subscribe(() => console.log("Map is ready!"));
}, 3000);
}
}
If i use this page as root it works perfect, but if i use another page as root and i push to the map page it don’t work, the navbar shows, the map try to loads(really buggy for like 1 sec and its get hidden) and then the ion content gets transparent/invisible and consequently the map.
Anyone have any idea what is happening?
I’m testing that on a real android device, not a browser, and i’m getting this._next is not a function in the console.
At the app.ts if you use the rootPage as MapPage it works perfect, but if you use as HomePage and in the homepage you click at the button to push the map page it don’t.
@aaronksaunders - Hey Aaron - I have been doing some further debugging. Seems that when I apply the recommended upgrade steps for beta 10 to your project it stops working. I then get a black screen.
this.platform.ready()
.then(
()=>{
// execute code here
}
);
2 - It’s better to call the plugin’s constructor on ngAfterViewInit.
The way the plugin works is that it looks for the element with the id you specified and it replaces it with the Google Maps component. If you call the method before the DOM is ready, the plugin will fail to find that element.
…
Also I think it’s worth mentioning that this plugin works only when you’re on a device/emulator. You will not see any results in the browser. If you need some sort of fallback you would have to implement that manually.
This works fine when I clone the project, then run npm install followed by cordova prepare
I load the app via Xcode and and run it on my device there are no errors and the map shows up fine. However I then follow the procedure mentioned here https://github.com/driftyco/ionic/blob/master/CHANGELOG.md#steps-to-upgrade-to-beta-10 to upgrade this project which is based on ionic beta 8 to the latest and greatest beta 10. I then try to run it again via Xcode and this time there are still no errors but now I have a black screen as per the image in my previous post.
So without using ngAfterViewInit I did manage to get the plugin to work reliably in ionic beta 8. Are you saying that for ionic beta 10 ngAfterViewInit is the crucial step to get things to work?
No, the code doesn’t really have to be in there. By the time platform.ready() and GoogleMaps.isAvailable() both resolve, your DOM is most likely to be ready. Using ngAfterViewInit or equivalent just helps by being on the safe side.
So in short, you need to wait for the following before being able to display a map: ondeviceready event which is platform.ready() in ionic2, GoogleMaps.isAvailable(), and the DOM to be ready.
isAvailable() checks if the plugin is available on the device (if the native SDKs are available)…
Also if you read above, I recommend waiting for the DOM to be ready as well before you try to create your map.
I’m not sure if these suggestions are the actual fix, but from my understanding of the plugin I find these steps necessary to have a map rendered successfully 100% of the time.