2017-05-10 15 views
0

我正在使用Google地图插件和地理位置插件的离子版Google地图上工作。使用位置更改后更新经纬度的地理定位功能来获取当前位置。 每一件事情都很好,但我面临的问题是我想将相机位置移动到当前正在改变位置的位置。当我在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); 
}); 
} 

} 

回答

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); 
相关问题