Created
July 4, 2016 16:02
-
-
Save jcmm33/af70cb41b8b8e5ea644d5431441097c1 to your computer and use it in GitHub Desktop.
Location Observable Sample
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public IObservable<GeoLocation> CurrentLocationObservable(LocationOptions options) | |
{ | |
IObservable<GeoLocation> observable = null; | |
if (!_observables.TryGetValue(options,out observable)) | |
{ | |
var coordinates = new Subject<GeoLocation> (); | |
var geoInstance = new GeoInstance (coordinates, options); | |
observable= Observable.Create<GeoLocation> ((o) => { | |
geoInstance.Start (); | |
var sub = coordinates. | |
Subscribe (o.OnNext, o.OnError, o.OnCompleted); | |
var cd = new CompositeDisposable (sub, | |
Disposable.Create (geoInstance.Stop), | |
Disposable.Create (() => this.Log ().Information ("Disposed"))); | |
return cd; | |
}).Replay(1).RefCount (); | |
_observables [options] = observable; | |
} | |
return observable; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment