Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc error - Observe geolocation updates #27597

Closed
fatalcaron opened this issue Dec 11, 2018 · 7 comments
Closed

Doc error - Observe geolocation updates #27597

fatalcaron opened this issue Dec 11, 2018 · 7 comments

Comments

@fatalcaron
Copy link

馃摎 Docs or angular.io bug report

Description

I try your example of geolocation updates via Observables and I got an error.

馃敩 Minimal Reproduction

What's the affected URL?**

https://angular.io/guide/observables

Reproduction Steps**

Copy paste your example in a new Angular project and run

馃敟 Exception or Error

ERROR TypeError: Cannot read property 'isStopped' of null



馃實 Your Environment

Angular 7.0.0
Rxjs 6.3.0

Anything else relevant?

Replace the callback and it work...
const { next, error } = observer;
By:

const onSuccess: PositionCallback = (pos: Position) => {
observer.next(pos);
};

const onError: PositionErrorCallback = (error) => {
observer.error(error);
};

@ericmartinezr
Copy link
Contributor

See if this PR fixes it #27260

@fatalcaron
Copy link
Author

Quick like a lightning!!!
Thanks

@fatalcaron
Copy link
Author

I spoke too fast, the PR does not solve the problem

@dariobraun
Copy link
Contributor

Any idea how to fix this?

@fatalcaron
Copy link
Author

@dariobraun Try this:

createWatchPosition(options?: PositionOptions): Observable<Position> {
  return new Observable((observer) => {
    // Get the next and error callbacks. These will be passed in when
    // the consumer subscribes.
    let watchId;

    const onSuccess: PositionCallback = (pos: Position) => {
      observer.next(pos);
    };

    const onError: PositionErrorCallback | any = (error) => {
      observer.error(error);
    };

    // Simple geolocation API check provides values to publish
    if (this.hasGeolocation) {
      watchId = navigator.geolocation.watchPosition(onSuccess, onError, options);
    } else {
      onError('Geolocation not available');
    }

    // When the consumer unsubscribes, clean up data ready for next subscription.
    return { unsubscribe() { navigator.geolocation.clearWatch(watchId); } };
  });
}

@rockument69
Copy link
Member

This was fixed by PR 34705. I am therefore closing this issue.

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jul 19, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

6 participants