Как добавить маркер с текстом и объявить ближайший маркерный текст с помощью ionic 4? - PullRequest
0 голосов
/ 19 сентября 2019

Я использую Google Map в Ionic 4 и на карте я добавил отметку с сообщением о конкретном месте.Мой вопрос заключается в том, когда пользователь будет перемещаться из-под этих отметок, я хочу, чтобы tts произнес сообщение от этих отметок.вот мой код:

   ngOnInit() {
    //getting all markers on map
    this.placeDataService.getCoords().then((data) => {
      this.placeData = data;
      this.displayGoogleMap();
      this.getMarkers(this.placeData);
    });
    //getting marker which are available in 1km radius
    this.fcmService.getMarkerList().then((data) => {
      this.markerlist = data;
      console.log(this.markerlist);
    });
    setInterval(data => {
      this.markerlenth = this.markerlist.length;
      //in constuctor i saved current location and getting here
      this.ttslat = localStorage.getItem("ttsClat");
      this.ttslong = localStorage.getItem("ttsClng");
      //this condition will check user moving or not, compare with current location vs user location if user move
      if (this.clat !== this.ttslat && this.clng !== this.ttslong) {
        setTimeout(data => {
          this.fcmService.getMarkerList().then((data) => {
            this.markerlist = data;
            console.log(this.markerlist);
          });
          //for loop to get message one by one
          for (let i = 0; i < this.markerlist.length; i++) {
            debugger;
            this.readLoc(this.markerlist[i]);
            console.log(this.markerlist[i]);
          }
        }, 2000)
      } else {
        console.log("no changes");
      }
    }, 120000);
  }

  readLoc(locmessage: any) {
    console.log(locmessage.Message);
    this.text = (locmessage.Message)
    this.tts.speak({
      text: this.text,
      //rate: this.rate / 10,
      // locale: this.locale
    }).then(() => {
      console.log('Success')
    }).catch((reason: any) => {
      console.log(reason)
    });
  }

Проблема в том, что этот код получает одноразовое сообщение, которое не запускается от всех маркеров.

json data

Array(6)
0: {Id: 13, Latitude: "23.074264731700133", Longitude: "72.5122116530348", Message: "test", State: "Gujarat", …}
1: {Id: 14, Latitude: "23.073193769048675", Longitude: "72.52036687909845", Message: "Don't worry be safe.", State: "Gujarat", …}
2: {Id: 17, Latitude: "23.076385975328805", Longitude: "72.5223851294902", Message: "Don't worry be safe.", State: "Gujarat", …}
3: {Id: 20, Latitude: "23.07646907995027", Longitude: "72.52504823433969", Message: "Don't worry be safe.", State: "Gujarat", …}
4: {Id: 21, Latitude: "23.076870448372684", Longitude: "72.51909001488002", Message: "Don't worry be safe.", State: "Gujarat", …}
5: {Id: 12, Latitude: "23.069357455856007", Longitude: "72.52311448687476", Message: "Don't worry be safe.", State: "Gujarat", …}
length: 6
__proto__: Array(0)
...