Googlmap.getCameraPosition()不适用于iOS

时间:2019-01-22 13:01:27

标签: google-maps ionic-framework ionic2

Googlemap.getCameraPosition()对于iOS而言不做任何事情,也不会阻止或捕获bolck,也不会在其中进行任何操作。

但是在android上,它运行正常。

GoogleMap的其他方法也不适用于iOS,对于iOS,指针永远不会指向 this.map.on(GoogleMapsEvent.MAP_READY)

import { Component, ViewChild, ElementRef, OnInit, AfterViewInit } from '@angular/core';
import { NavController,NavParams,Events, ViewController, Platform } from 'ionic-angular';
import { GoogleMap, GoogleMapsEvent, GoogleMapsLatLng,CameraPosition, Geolocation } from 'ionic-native';
import _ from 'lodash';
@Component({
selector: 'page-map-modal',
templateUrl: 'map-modal.html'
})
export class MapModalPage implements OnInit,AfterViewInit  {
@ViewChild('map') mapElement: ElementRef;

lat: any;
lng: any;
map:GoogleMap; 
target:any;
position:any;
constructor(public navCtrl: NavController,
          public viewCtrl: ViewController,
          public platform: Platform,
          public events: Events,
          private alert:AlertController,
          private navParam: NavParams) {
this.target = this.navParam.get('location');
}


//get current location of user
ngOnInit() {
Geolocation.getCurrentPosition().then((result)=>{
    this.position =  result;   
  },(error)=>{
    // console.log(error,"error occured while getting geolocation");
})
}


ngAfterViewInit(){
this.platform.ready().then(() => {
    this.loadMap();
});
}




loadMap(){
let location = null;
if(this.target['lat'] && this.target['lng']){
    location = new GoogleMapsLatLng(Number(this.target['lat']),Number(this.target['lng']));
}else{
  location = new GoogleMapsLatLng(24.795464,46.699796);
}

this.map = new GoogleMap('map', {
  'backgroundColor': 'white',
  'controls': {
    'compass': true,
    'myLocationButton': true,
    'indoorPicker': true,
    'zoom': true
  },
  'gestures': {
    'scroll': true,
    'tilt': false,
    'rotate': true,
    'zoom': true
  },
  'camera': {
    'latLng': location,
    'tilt': 20,
    'zoom': 15,
    'bearing': 50
  }
});
this.map.setCenter(location);
this.map.on(GoogleMapsEvent.MAP_READY).subscribe(() => {

  this.map.refreshLayout();
  this.map.clear();

  if((_.isEmpty(this.target['lat']) || this.target['lat'] == '0') &&  (_.isEmpty(this.target['lng']) || this.target['lng'] == '0')){ 
    this.map.getMyLocation().then((target)=>{
    location = new GoogleMapsLatLng(target.latLng.lat,target.latLng.lng);

      let position: CameraPosition = {
        target: location,
        zoom: 15,
        tilt: 30,
        bearing: 50
      };
      // // move the map's camera to position
      this.map.moveCamera(position);
      this.map.setCenter(location);
      // console.log(target.latLng.lat, target.latLng.lng,"current user location");
    },(error)=>{
      // console.log(error,"error in getting current location");
    })
  }   
});
}


dismiss(){
this.navCtrl.pop();
}


pickLocationAndDismiss(){
let target;
this.map.getCameraPosition().then((data)=>{
  target = data.target;
  this.events.publish('latlng:map',target);
}).catch(err=>{
console.log(err)
});

this.navCtrl.pop();
}


}

0 个答案:

没有答案