Hi,
I’m working on an application where I need to use the services of Google Maps, I read the documentation of Ionic Native. But when run the application on the device, the map doesn’t load correctly:
Plugin:
“@ionic-native/geolocation”: “^3.7.0”,
“@ionic-native/google-maps”: “^3.7.0”,
Ionic Info
Your system information:
Cordova CLI: 7.0.0
Ionic Framework Version: 3.1.1
Ionic CLI Version: 2.2.3
Ionic App Lib Version: 2.2.1
Ionic App Scripts Version: 1.3.7
ios-deploy version: Not installed
ios-sim version: Not installed
OS: Linux 4.4
Node Version: v4.2.6
Xcode version: Not installed
HTML
<ion-content scroll="false">
<div id="map"></div>
</ion-content>
CSS:
ion-app._gmaps_cdv_ .nav-decor {
background-color: transparent !important;
}
page-google-map {
#map {
height: 100%;
}
}
Page:
import { Component } from '@angular/core';
import { IonicPage, NavController } from 'ionic-angular';
import { GoogleMaps, GoogleMap, GoogleMapsEvent, LatLng, CameraPosition, MarkerOptions } from '@ionic-native/google-maps';
import { Geolocation, Geoposition } from '@ionic-native/geolocation';
@IonicPage()
@Component({
selector: 'page-google-map',
templateUrl: 'google-map.html',
})
export class GoogleMapPage {
constructor(
public navCtrl: NavController,
private googleMaps: GoogleMaps,
private geolocation: Geolocation
) {
}
ngAfterViewInit() {
this.geolocation.getCurrentPosition().then((res) => {
this.loadMap(res);
})
.catch((error) =>{
console.log(error);
});
}
loadMap(postion: Geoposition) {
let latitude = postion.coords.latitude;
let longitud = postion.coords.longitude;
let element: HTMLElement = document.getElementById('map');
let map: GoogleMap = this.googleMaps.create(element);
let myPosition: LatLng = new LatLng(latitude,longitud);
let position: CameraPosition = {
target: myPosition,
zoom: 15,
tilt: 30
};
map.one(GoogleMapsEvent.MAP_READY).then(()=>{
console.log('Map is ready!');
map.moveCamera(position);
let markerOptions: MarkerOptions = {
position: myPosition,
title: 'Tu ubicación...'
};
map.addMarker(markerOptions);
});
}
}
app.module.ts:
providers: [
Geolocation,
GoogleMaps
Regards