我一直在與谷歌地圖插件白衣離子V2-3,地圖效果很好的第一頁上,你可以在這裏看到:谷歌地圖2
FYI:我已經安裝了插件和生成的API密鑰
這是我的代碼:
地圖view.html
<ion-header>
<ion-navbar>
<ion-title>mapView</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<button ion-button block (click)="mapa2()">Next Page</button>
<ion-list>
<ion-item>
<ion-label>Nick</ion-label>
<ion-input type="text" [(ngModel)]="doc"></ion-input>
</ion-item>
<ion-item>
<ion-label>Password</ion-label>
<ion-input type="password" [(ngModel)]="pss"></ion-input>
</ion-item>
<button ion-button full color="primary" (click)="login()">
Login
</button>
</ion-list>
<div #map id="map" style="height:100%;"></div>
</ion-content>
地圖view.ts
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, Platform } from 'ionic-angular';
import {
GoogleMaps,
GoogleMapsEvent,
LatLng
} from '@ionic-native/google-maps';
@IonicPage()
@Component({
selector: 'page-map-view',
templateUrl: 'map-view.html',
})
export class MapView {
public doc:string;
public pss:string;
constructor(public navCtrl: NavController,
public navParams: NavParams,
private googleMaps: GoogleMaps,
public platform:Platform,
public loginCtrl:LoginService) {
}
ionViewDidLoad() {
console.log('ionViewDidLoad MapView');
}
mapa2(){
this.navCtrl.push('Map2');
}
ngAfterViewInit() {
this.platform.ready().then(() => {
this.loadMap();
});
}
loadMap() {
let element: HTMLElement = document.getElementById('map');
let map = this.googleMaps.create(element);
console.log("Inicializo el mapa");
map.one(GoogleMapsEvent.MAP_READY).then((data:any)=>{
let myPosition = new LatLng(43.0741904, -89.3809802);
map.animateCamera({target: myPosition,zoom:10});
map.addMarker({
'position':myPosition,
'title': 'hi!'
});
}).catch(()=>console.log("GoogleMap is not available"));
}
}
在第二頁不再顯示在地圖,但在功能上輸入:
的代碼(相同):
map2.html
<ion-header>
<ion-navbar>
<ion-title>map2</ion-title>
</ion-navbar>
</ion-header>
<ion-content>
<div #map id="map" style="height:100%;"></div>
</ion-content>
map2.ts
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams, Platform } from 'ionic-angular';
import {
GoogleMaps,
GoogleMapsEvent,
LatLng
} from '@ionic-native/google-maps';
@IonicPage()
@Component({
selector: 'page-map2',
templateUrl: 'map2.html',
})
export class Map2 {
constructor(public navCtrl: NavController, public navParams: NavParams,
public platform:Platform,
private googleMaps: GoogleMaps) {
}
ionViewDidLoad() {
console.log('ionViewDidLoad Map2');
}
ngAfterViewInit() {
this.platform.ready().then(() => {
this.loadMap();
});
}
loadMap() {
let element: HTMLElement = document.getElementById('map');
let map = this.googleMaps.create(element);
console.log("Inicializo el mapa");
map.one(GoogleMapsEvent.MAP_READY).then((data:any)=>{
let myPosition = new LatLng(43.0741904, -89.3809802);
map.animateCamera({target: myPosition,zoom:10});
map.addMarker({
'position':myPosition,
'title': 'Hi2'
});
}).catch(()=>console.log("GoogleMap is not available"));
}
}
我怎樣才能顯示在其他網頁地圖時上的應用程序導航!
由於提前,
嘗試使用V2插件版本https://github.com/mapsplugin/cordova-plugin-googlemaps-doc/blob/master/v2.0.0/README.md。 –