1
votes

I'm using geolocation in my Ionic app, and I would like to use the method watchposition to check whenever (for example) the user turns off GPS while watching his position to catch the error and show a message on screen.
Following this guide I'm doing this:

let watch = this.geolocation.watchPosition();
  watch.subscribe((data)=>{

  })

but I can't find a method to catch errors while being subscribed to data. Is there a way to achieve this?

1

1 Answers

1
votes

If I understand correctly, you want to catch errors thrown from your watchPosition().

According to the API docs it returns Observable<Position>. This means you can use the standard way of setting an error handler in your subscribe function. It can take 3 parameters. subscribe(onsuccess,onerror,oncompletion).

let watch = this.geolocation.watchPosition();
  watch.subscribe((data)=>{

  },error => {
      console.log(error); //error handling
  })