Ионная геолокация - как обновить позицию? - PullRequest
0 голосов
/ 09 мая 2018

Я новичок в ионной и только что исправленной геолокации в моем приложении.Теперь я могу видеть свою позицию на карте, но у меня проблема с позицией, которая не обновляется на карте.Я перепробовал все возможные способы и много гуглил, а также читал здесь, на Stackoverflow, но все еще ничего не работает.Положение не обновляется.Можете ли вы взглянуть на мой код и сказать, что я сделал не так?

 loadMap() {

      this.geolocation.getCurrentPosition().then((position) => {
      let latLng = new google.maps.LatLng(position.coords.latitude,position.coords.longitude);
      let mapOptions = {
        center: latLng,
        zoom: 15,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      }
      this.map = new google.maps.Map(this.mapElement.nativeElement, mapOptions);


      //Red pin shows users position on the map
      var myPositionMarker = new google.maps.Marker({
        map: this.map,
        position: latLng, 
        icon: 'assets/imgs/pins/redpin.png',
        enableHighAccuracy:true
      })


      //For position update(this is a code which is not working)
        let watch = this.geolocation.watchPosition();
        watch.subscribe((data) => {
       // data can be a set of coordinates, or an error (if an error occurred).
       // data.coords.latitude
       // data.coords.longitude
       });

1 Ответ

0 голосов
/ 10 мая 2018

Вы можете попробовать использовать метод 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);} );
}
...