【发布时间】:2018-04-05 09:43:12
【问题描述】:
https://github.com/mapsplugin/cordova-plugin-googlemaps
按照所有说明仍然没有加载地图。
在这里查看解决方案。
应用了所有的解决方案仍然无法正常工作。
HTML:
<div id="map_canvas"></div>
CSS:
page-home {
#map_canvas {
height: 100%;
width: 100%;
}
}
ts:
import { NavController, Platform } from 'ionic-angular';
import { GoogleMaps, GoogleMap, GoogleMapsEvent, GoogleMapOptions, CameraPosition, MarkerOptions, Marker } from '@ionic-native/google-maps';
import { Component } from "@angular/core";
@Component({
selector: 'page-home',
templateUrl: 'home.html'
})
export class HomePage {
map: GoogleMap;
constructor(private gm: GoogleMaps, private platform: Platform) { }
ionViewDidLoad() {
this.platform.ready().then(() => {
// this.loadMap();
setTimeout(this.loadMap.bind(this), 1000);
});
}
getMyLocation() {
this.map.getMyLocation().then(location => {
alert('success!');
alert(JSON.stringify(location));
}).catch(err => {
alert('failure!');
alert(JSON.stringify(location));
});
}
loadMap() {
let mapOptions: GoogleMapOptions = {
camera: {
target: {
lat: 43.0741904,
lng: -89.3809802
},
zoom: 18,
tilt: 30
}
};
this.map = GoogleMaps.create('map_canvas', mapOptions);
this.map.one(GoogleMapsEvent.MAP_READY)
.then(() => {
alert('Map is ready!');
this.map.addMarker({
title: 'Ionic',
icon: 'blue',
animation: 'DROP',
position: {
lat: 43.0741904,
lng: -89.3809802
}
})
.then(marker => {
marker.on(GoogleMapsEvent.MARKER_CLICK)
.subscribe(() => {
alert('clicked');
});
});
});
}
}
【问题讨论】:
标签: google-maps ionic3 cordova-plugins