首页 文章

将相机移动到离子 Map 中的当前位置

提问于
浏览
0

我正在使用谷歌 Map 插件和地理定位插件在离子谷歌 Map 上工作 . 并使用地理定位的watchposition函数获取当前位置,该位置在位置更改后更新lat . 一切都很好,但我面临的问题是我想将相机位置移动到我当前通过改变位置而改变的位置 . 当我在movCamera函数中设置固定的lat长时,它将相机移向这些latlong,但是当我将其设置为当前位置时,它将 Map 移动到其他位置但不是我的 .

谁能告诉我这是什么问题?

这是代码 . . .

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);
});
}

}

1 回答

  • 0
    let ionic1: LatLng = new LatLng(33.635322,73.073989);
    

    在这里,您将位置坐标分配给 ionic1 变量 . 但是在Camposition选项中,您为目标提供了名为 ionic 的变量 .

    // create CameraPosition
    let Camposition: CameraPosition = {
        target: ionic,
        zoom: 22,
        tilt: 30
     };
    

    它应该更正为 ionic1 .

    // create CameraPosition
    let Camposition: CameraPosition = {
        target: ionic1,
        zoom: 22,
        tilt: 30
     };
    

    也不要使用这种变量名 . 使用适当的命名约定以避免这些类型的错误 . 选择如下 .

    let defaultLocation: LatLng = new LatLng(33.635322,73.073989);
    

相关问题