How to stop the code from being execute or wait for a first line to completely execute


#1

Okay so what I want to do is wait for a location service to fetch the coords and then I’m going to execute my other functions(lines of code).

//in my TS file.
this.locationAccuracy.request(this.locationAccuracy.REQUEST_PRIORITY_HIGH_ACCURACY)
.then(() => {

    this.locService.getLocation();

    //Execute this function only when you have got the coords from this locService.
    this.getList();

  }, error => this.ui.showToast('Please enable GPS location', false, '')
  );

IN my Service file

this.geolocation.watchPosition()
  .filter((p) => p.coords !== undefined) //Filter Out Errors
  .subscribe(position => {
    console.log(position.coords.latitude + ' ' + position.coords.longitude);
    this.lat = position.coords.latitude;
    this.lng = position.coords.longitude;

  });

What to do ?
Please help, I think this can be achieved using async/await but I dont know how to use them?


#2

Put the subscribe in the calling ts and let the service return the obervable

Tom