我仍在学习 RxJava,我知道什么是 Observable 和 Observers 的基本知识,但仍然困惑如何、何时何地使用过滤器、地图、平面图等
您有什么好的建议如何将此代码转换为 RxJava 吗?
void locationChanged(LocationResult locationResult) {
for (Location location : locationResult.getLocations()) {
Double lat = location.getLatitude();
Double lng = location.getLongitude();
boolean isMock;
if (Build.VERSION.SDK_INT >= 18) {
isMock = location.isFromMockProvider();
} else {
isMock = !Settings.Secure.getString(getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION).equals("0");
}
for (int k = 0; k < offices.size(); k++) {
Office office = offices.get(k);
Double d_lat = Double.valueOf(office.getOc_lat());
Double d_long = Double.valueOf(office.getOc_long());
Double d_radius = Double.valueOf(office.getOc_radius());
Location.distanceBetween(lat, lng, d_lat, d_long, resultApi);
String s_distanceToOffice = String.valueOf(resultApi[0]);
Double d_distanceToOffice = Double.parseDouble(s_distanceToOffice);
//Log.e(TAG, "locationChanged: Distance -> " + d_distanceToOffice);
// check-in in radius
if (d_distanceToOffice < d_radius) {
buttonOutOfRadius.setVisibility(View.GONE);
progressBarPosition.setVisibility(View.GONE);
哪些代码需要更改而无需更改?我做过这样的事情:
Observable.fromIterable(offices)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe()
我是否需要将循环“for(..)”中的代码复制粘贴到“oNext(Office office)”中?
很高兴从您的经验中得知。
GCT1015
相关分类