/**
* Yields periodical location updates.
*
* This observable will never call onComplete() thus manual unsubscribe() is necessary.
*
* When using setExpirationDuration() or setNumUpdates() or setExpirationTime() the observable
* will not terminate automatically and will just stop emitting new items without releasing any
* resources.
*
* @return an Observable that returns Location items.
*/
@SuppressWarnings("WeakerAccess") // It's an entry point.
public static Observable<Location> locationUpdates(final Context context,
final LocationRequest locationRequest) {
return Observable.create(new ObservableOnSubscribe<Location>() {
@Override
public void subscribe(ObservableEmitter<Location> e) throws Exception {
final LocationUpdatesHelper locationUpdatesHelper = new LocationUpdatesHelper(
context, new GoogleApiClientFactoryImpl(),
new FusedLocationProviderFactoryImpl(), e, locationRequest);
e.setCancellable(new Cancellable() {
@Override
public void cancel() throws Exception {
locationUpdatesHelper.stop();
}
});
locationUpdatesHelper.start();
}
});
}
RxLocation.java 文件源码
java
阅读 27
收藏 0
点赞 0
评论 0
项目:RxLocation
作者:
评论列表
文章目录