私は2つの観測値を結合し、AndroidSchedules.mainThread()で "combine関数"を実行したいと考えています。 .observeOn(AndroidSchedules.mainThread())を追加しましたが、 "java.lang.IllegalStateException:メインスレッドではありません"というメッセージが表示されます。mainThreadのcombineLatest()関数
Observable<List<Post>> animateCameraAndGetPostsByProjection = Observable.combineLatest(
mapObservableProvider.getMapReadyObservable(),
LocationService.getUpdatedOrLastKnownLocation(this),
(googleMap, location) -> {
CameraUpdate cameraUpdate = CameraUpdateFactory.newLatLngZoom(new LatLng(location.getLatitude(),location.getLongitude()),15);
googleMap.moveCamera(cameraUpdate);
return googleMap.getProjection().getVisibleRegion();
})
.flatMap(vr -> new RestService().getApi().getPostsByMapProjection(vr.farLeft.latitude,vr.farLeft.longitude,vr.nearRight.latitude,vr.nearRight.longitude))
.observeOn(AndroidSchedulers.mainThread());
どこにエラーがありますか? APIでは、最終結果の受信ではなくメインスレッドで呼び出す必要があります。 – akarnokd
エラーはgoogleMap.moveCamera(cameraUpdate)を指しています。私は、この関数はメインスレッドで実行する必要がありますが、私はどのように組み合わせ関数のスレッドを設定するのか分からないことを知っている。 –
observeOnを両方のソースに置きます。両方とも値がある場合、関数はメインスレッドで実行されます。 – akarnokd