【问题标题】:Move Camera to current position in ionic maps将相机移动到离子贴图中的当前位置
【发布时间】:2017-10-09 04:02:43
【问题描述】:

我正在使用谷歌地图插件和地理定位插件在 ionic 中处理谷歌地图。并使用地理位置的监视位置功能获取我的当前位置,该功能在位置更改后很长时间更新。 一切都很好,但我面临的问题是我想将相机位置移动到通过改变位置而改变的当前位置。当我在 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);
});
}

}

【问题讨论】:

    标签: google-maps ionic-framework geolocation maps ionic-native


    【解决方案1】:
    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);
    

    【讨论】:

      猜你喜欢
      • 2021-10-09
      • 2018-09-13
      • 2016-06-15
      • 1970-01-01
      • 2022-01-05
      • 1970-01-01
      • 2017-10-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多