【发布时间】:2017-11-08 06:07:34
【问题描述】:
我可以在我的Android 设备上获得GoogleMap,问题是它没有指向我的current location。
我已经安装了这两个包:
$ ionic cordova plugin add cordova-plugin-googlemaps --variable API_KEY_FOR_ANDROID="YOUR_ANDROID_API_KEY_IS_HERE" --variable API_KEY_FOR_IOS="YOUR_IOS_API_KEY_IS_HERE"
$ npm install --save @ionic-native/google-maps
下面是我的 google 地图在我的 android 设备上的样子
下面是我的代码:
ionViewDidLoad() {
console.log('ionViewDidLoad GoogleMapTestPage');
this.loadMap();
}
ngAfterViewInit() {
//this.loadMap();
}
loadMap() {
// create a new map by passing HTMLElement
let element: HTMLElement = document.getElementById('map');
let map: GoogleMap = this.googleMaps.create(element);
// listen to MAP_READY event
// You must wait for this event to fire before adding something to the map or modifying it in anyway
map.one(GoogleMapsEvent.MAP_READY).then(
() => {
console.log('Map is ready!');
// Now you can add elements to the map like the marker
}
);
// create LatLng object
let ionic: LatLng = new LatLng(43.0741904,-89.3809802);
// create CameraPosition
let position: any = {
target: ionic,
zoom: 18,
tilt: 30
};
// move the map's camera to position
map.moveCamera(position);
// create new marker
let markerOptions: MarkerOptions = {
position: ionic,
title: 'Ionic'
};
const marker:any = map.addMarker(markerOptions)
.then((marker: Marker) => {
marker.showInfoWindow();
});
}
我的 html 代码
<ion-content>
<div #map id="map" style="height:100%;"></div>
</ion-content>
我的问题:
如何在上面的代码中指向我的current location!!
请帮助我,因为我是 ionic 3 的新手,我只是想指出当前用户
谷歌上的位置!!
【问题讨论】:
标签: android google-maps cordova ionic3 ionic-native