我正在使用谷歌地图插件和地理定位插件在离子中使用谷歌地图。并使用地理位置的监视位置功能获取我当前的位置,该功能在位置更改后很长时间更新。一切都很好,但我面临的问题是我想将相机位置移动到通过改变位置而改变的当前位置。当我在 movCamera 函数中设置固定的经纬度时,它会将相机移向这些经纬度,但是当我将其设置为我当前的位置时,它会将地图移动到其他位置,但不是我的。
谁能告诉我是什么问题??
这是代码。. .
export class HomePage {
x: number = 0;
y: number = 0;
constructor(public navCtrl: NavController,private googleMaps: GoogleMaps, public platform:Platform,private geolocation: Geolocation) {
platform.ready().then(() => {
this.loadMap();
});
}
loadMap() {
// create a new map by passing HTMLElement
let element: HTMLElement = document.getElementById('map');
this.geolocation.watchPosition().subscribe((position) => {
this.x = position.coords.longitude;
this.y = position.coords.latitude;
let ionic: LatLng = new LatLng(this.x,this.y);
let map: GoogleMap = this.googleMaps.create(element,{
'backgroundColor': 'white',
'controls': {
'compass': true,
'myLocationButton': true,
'indoorPicker': true,
'zoom': true
},
'gestures': {
'scroll': true,
'tilt': true,
'rotate': true,
'zoom': true
}
});
// 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!');
});
let ionic1: LatLng = new LatLng(33.635322,73.073989);
// create CameraPosition
let Camposition: CameraPosition = {
target: ionic,
zoom: 22,
tilt: 30
};
// move the map's camera to position
map.moveCamera(Camposition);
}, (err) => {
console.log(err);
});
}
}