离子地理位置 - 如何更新位置?

时间:2018-05-09 16:18:11

标签: ionic-framework geolocation

我是Ionic的新手,只是修复了我的应用中的地理位置。我现在可以在地图上看到我的位置,但我在地图上没有更新位置的问题。我尝试了所有可能的方法并google了很多,也在Stackoverflow上阅读,但仍然没有任何工作。职位没有更新。请你看看我的代码并告诉我我做错了什么?

@ViewChild('autoC') auto: HTMLElement;

1 个答案:

答案 0 :(得分:0)

您可以尝试使用watchPosition方法代替getCurrentPosition类似的方法:

loadMap() {

  this.geolocation.watchPosition().subscribe((position) => {
      let latLng = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
      let marker = new google.maps.Marker({
        map: this.map,
        icon:  'assets/imgs/pins/redpin.png',
        position: latLng,
        enableHighAccuracy:true
       });
      let message = "Current Position";
      this.addInfoWindow(marker, content);
  }, (err) => {console.log(err);} );
}