Geolocation Ionic 3 Issue

Hello all,

I’m having an issue with the Geolocation plugin.

When I subscribe to watchPosition function it returns an Observable.

After that , when I will leave the View , I want to unsubscribe from the Observable.

And I receive these message : is not a function

Post your piece of code here.That may help you to get fix for the issue :smiley:

public watch: Observable<Geoposition>; => {
          let miPosicion = new LatLng(data.coords.latitude, data.coords.longitude);
          console.log("Entro en subscribe")
          if (this.myTarget != null) {
  { icon: 'assets/imgs/customMarker.jpg', position: miPosicion }).then((marker) => { this.myTarget = marker });
          } else {
  { icon: 'assets/imgs/customMarker.jpg', position: miPosicion }).then((marker) => { this.myTarget = marker });

ionViewWillLeave() {
    if ({

So , when I leave the View , i want to unsubscribe from the observable. But it doesn’t recognize unsubscribe() like a function.


Iam little bit confused :confused:
I think there is no unsubscribe funtion for geolocation.
you may be use geolocation.clearWatch function if you are using
ionic geolocation plugin native geolocation

By the Ionic documentation , it has to be like these ->

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

// To stop notifications

And that’s what I have…

1 Like

Hi@hiperium You had better the ionic official documentation for the reference